403 响应代码 - 使用 Cowin setu API 时请求被阻止

shi*_*rma 10 javascript node.js express amazon-cloudfront restapi

我只是想在 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>
Run Code Online (Sandbox Code Playgroud)

这是我的 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", function(req, 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,res,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!");
 });
Run Code Online (Sandbox Code Playgroud)

我希望这个问题会解决

谢谢

小智 7

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)
Run Code Online (Sandbox Code Playgroud)


小智 3

使用以下

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'
    }
};
Run Code Online (Sandbox Code Playgroud)