程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了403 响应代码 - 使用 Cowin setu API 时请求被阻止大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决403 响应代码 - 使用 Cowin setu API 时请求被阻止?

开发过程中遇到403 响应代码 - 使用 Cowin setu API 时请求被阻止的问题如何解决?下面主要结合日常开发的经验,给出你关于403 响应代码 - 使用 Cowin setu API 时请求被阻止的解决方法建议,希望对你解决403 响应代码 - 使用 Cowin setu API 时请求被阻止有所启发或帮助;

我只是想在 nodeJs 中使用 Cowin Setu API(印度)来发出 covID 疫苗警报。但是我遇到了一些奇怪的事情,每当我点击获取请求时,我都会收到来自 cloudfront 的 403 响应代码说“请求已阻止”,但邮递员和浏览器也是如此。请帮助我

出现此错误:-

<!DOCTYPE HTML PUBliC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/HTML4/loose.dtd">
<HTML><head><Meta http-EQUIV="Content-Type" CONTENT="text/HTML; charset=iso-8859-1">
<title>ERROR: The request Could not be satisfIEd</title>
</head><BODY>
<H1>403 ERROR</H1>
<H2>The request Could not be satisfIEd.</H2>
<HR noshade size="1px">
request blocked.
We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later,or contact the app or website owner.
<BR clear="all">
If you provIDe content to customers through CloudFront,you can find steps to troubleshoot and Help prevent this error by revIEwing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
request ID: Q1RZ94qgFP6AjUUKE4e9urMB85VejcqMbaJO6Y8Xq5Qp4kNjDBre9A==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>

这是我的 nodeJs 代码:

var express = require("express");
var app = express();
var bodyParser = require("body-parser");
const axios = require("axios");
const { Telegram } = require("telegraf");
const fetch = require("node-fetch");
var cors = require('cors');
var request=require('request');


const tg = new Telegram(process.env.bOT_TOKEN);
const bot = new Telegram(process.env.bOT_TOKEN,{
polling: true
});

//bot.start((ctX) => ctx.reply('Welcom to CovID Vaccine Finder'))

/*bot.hears("about",ctx => {
ctx.reply("hey,I am CoviBot!");
});
bot.launch();*/

app.use(bodyParser.Json());

app.use(cors());



app.use(
bodyParser.urlencoded({
extended: true
})
);

app.get("/",function(req,res) {
res.send("Welcom to CovID Vaccine Finder");
});

app.get("/test",res,next) {
var d = new Date();
var options = {
year: "numeric",month: "2-digit",day: "2-digit"
};

var date = String(d.tolocaleDateString("en",options));
date = date.replace(/\//g,"-");
console.log(datE);

const URL =
"https://cdn-API.co-vin.in/API/v2/appointment/sessions/public/findByPinpincode=110088&date=13-05-2021";

var options = { 
url: URL,method: 'GET',headers: {
  'Accept-EnCoding': 'gzip,deflate','Accept-Language': 'en-GB,en;q=0.8,en-US;q=0.6,hu;q=0.4','Cache-Control': 'max-age=0',Connection: 'keep-alive',Host: 'cdn-API.co-vin.in','User-Agent': 'request',}
 };
 request(options,function(err,body){
  let Json = body;
 console.log(Json);
 });


const txt = "Finding vaccine centres for you....";
//tg.sendmessage(process.env.GROUP_ID,txt);
res.send(txt);


});



 // Finally,start our server
 app.Listen(process.env.PORT,function() {
 console.log("CovID app Listening on port 3000!");
 });

希望这个问题能解决

谢谢

解决方法

我在请求中添加了一个 user-agent 标头,以便 API 能够识别出我的请求来自浏览器,而不是脚本。

headers = {
  'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/56.0.2924.87 Safari/537.36',}
url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDiStrict?diStrict_id=303&date="+date
response = requests.get(url,headers=headers)
,

使用以下内容

var options = { 
url: URL,method: 'GET',headers: {
        Host: 'cdn-api.co-vin.in','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/90.0.4430.93 Safari/537.36'
    }
};
,

试试这些标题他们在本地服务器(非生产)上为我工作

    let options = {
    headers: {
      "user-agent":
        "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/90.0.4430.93 Safari/537.36",},};

这些在生产环境中不起作用,因为 Cowin API 是地理围栏的,不能从印度以外的 IP 地址访问。在像 Heroku 这样的大多数免费托管网站中,印度 IP 不是一种选择。因此,替代解决方案可能是将 AWS、GCP、Azure 与印度服务器一起使用(尚未尝试)。

- https://github.com/cowinapi/developer.cowin/issues/228

,

该 api 似乎被禁止在印度境外使用。尝试在印度服务器中结合一些印度代理/使用

,

您必须使用用户代理标识符 API 请参这个 https://devcenter.heroku.com/articles/useragentidentifier#using-with-python

,

您必须按以下格式提出请求,我附上了状态元数据 API 的示例格式:

curl --LOCATIOn --request GET 'https://cdn-api.co-vin.in/api/v2/admin/LOCATIOn/states' --header '接受语言:hi_iN' --header ' Accept: application/json' --header 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/90.0.4430.93 Safari/537.36'

,

好的,如果你想在本地工作,你可以使用

 let headers = {
    'accept': 'application/json','Accept-Language': 'hi_iN','X-requested-With': 'XMLhttprequest','User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/83.0.4103.97 Safari/537.36',}

现在如果你想部署到 Heroku 或 firebase,那么它会返回 403,我认为主要是他们阻止了来自印度服务器的任何 IP 访问。

Github 链接:https://github.com/manojkumar3692/reactjs_nodejs_cowin

我会在这里通知你

大佬总结

以上是大佬教程为你收集整理的403 响应代码 - 使用 Cowin setu API 时请求被阻止全部内容,希望文章能够帮你解决403 响应代码 - 使用 Cowin setu API 时请求被阻止所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。