cowinapi / developer.cowin

This group is created to facilitate technical and integration discussions related to cowin platform. API related contents can be obtained at API setu portal https://apisetu.gov.in/public/marketplace/api/cowin
115 stars 30 forks source link

The request could not be satisfied: 403 ERROR #228

Closed indrajeetgour closed 3 years ago

indrajeetgour commented 3 years ago

Since I was trying to call the public API I am getting the following response, please let me know if I am making some mistake or anything that I need to fix.

code snippet for the same:(passing both pin_code and given_date in expected format)

URL = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode={}&date={}".format(
    pin_code, given_date)

header = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36'}

result = requests.get(URL, headers=header)
print(result.text)
<!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: mo4dgtccAh8iMewIbrv_PrWKuqwZMbESimjzodoLLGDr0DJgM1skVw==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>
<!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: MkY_9o_Wo7dFvn-fxSLw5nnjXUy3nLROMxAR15b7SQUWt9Ckq21mWA==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>
rohandhamapurkar commented 3 years ago

If you have made more than 100 requests per 5 min from your IP address then the requests start getting blocked with this same 403 error.

ninjabhishek commented 3 years ago

On top of this, make sure the requests are being sent from an Indian IP address. However, Indian IPs are rejected if you are using Digitalocean server as well. The above error code is because of IP not being detected as Indian origin

indrajeetgour commented 3 years ago

On top of this, make sure the requests are being sent from an Indian IP address. However, Indian IPs are rejected if you are using Digitalocean server as well. The above error code is because of IP not being detected as Indian origin

Thanks for let me know this... I was using VPN. Now it is working fine.. Thanks

Raxy45 commented 3 years ago

On top of this, make sure the requests are being sent from an Indian IP address. However, Indian IPs are rejected if you are using Digitalocean server as well. The above error code is because of IP not being detected as Indian origin

Thanks for let me know this... I was using VPN. Now it is working fine.. Thanks

Can you let me know what changes you made to your code ?! I'm using NodeJS and the app is deployed on heroku

saran-surya commented 3 years ago

@indrajeetgour , Kindly let us know the steps, you added in. Were you using VPN in your local machine or did this error occur in production ?

ninjabhishek commented 3 years ago

@Raxy45 heroku servers are not located in India. you will not be able to hit APIs from there. you should move your code to AWS, GCP aur Azure servers in India.

saran-surya commented 3 years ago

@ninjabhishek , we can hit the Indian API through a server proxy, I have a package for it if you are using node JS app.

ninjabhishek commented 3 years ago

@saran-surya have you tried it in a prod server on any cloud providers? heroku is a PaaS and would not allow you to do these, and other cloud providers give you their public IP which I don't think you can change, since they must be having the public ip and actual server behind a routing table which would be disrupted when you use server proxy there. This is just my assumption, please let me know if I am wrong and you have done this successfully on public cloud servers.

Also, what is the package?

saran-surya commented 3 years ago

Yes @ninjabhishek , I have done this in HEROKU US based server, and it is working fine, Like the main idea is to use your local IP and wrap the server on top of it, Thus you have to login to the proxy room in your client and change them,

The package is https://github.com/saran-surya/cassata, Also there is documentation on setting up the server and accessing them, Hope it helps 😉

indrajeetgour commented 3 years ago

On top of this, make sure the requests are being sent from an Indian IP address. However, Indian IPs are rejected if you are using Digitalocean server as well. The above error code is because of IP not being detected as Indian origin

Thanks for let me know this... I was using VPN. Now it is working fine.. Thanks

Can you let me know what changes you made to your code ?! I'm using NodeJS and the app is deployed on heroku

I just called my api from India hosted vm instead.

saran-surya commented 3 years ago

On top of this, make sure the requests are being sent from an Indian IP address. However, Indian IPs are rejected if you are using Digitalocean server as well. The above error code is because of IP not being detected as Indian origin

Thanks for let me know this... I was using VPN. Now it is working fine.. Thanks

Can you let me know what changes you made to your code ?! I'm using NodeJS and the app is deployed on heroku

I just called my api from India hosted vm instead.

Kindly elaborate the steps as they will be helpful.

indrajeetgour commented 3 years ago

@indrajeetgour , Kindly let us know the steps, you added in. Were you using VPN in your local machine or did this error occur in production ?

I used the api call from my local machine where as I used VPN which was in Germany before I switch to India, and it is working now. I think govt has restricted the access as per country.

saran-surya commented 3 years ago

@indrajeetgour , Kindly let us know the steps, you added in. Were you using VPN in your local machine or did this error occur in production ?

I used the api call from my local machine where as I used VPN which was in Germany before I switch to India, and it is working now. I think govt has restricted the access as per country.

Yes they have GEO-FENCED the public data, thus they can prevent people from booking slots from other countries, for people in India,

AkshayMathur92 commented 3 years ago

On top of this, make sure the requests are being sent from an Indian IP address. However, Indian IPs are rejected if you are using Digitalocean server as well. The above error code is because of IP not being detected as Indian origin

Yeah, I am facing the same issue. Why is this happening ?

ninjabhishek commented 3 years ago

@AkshayMathur92 they have done this to make sure people abroad do not put load on the api, and also because the vaccination drive is only for Indian people.

Which server or cloud are you facing this issue in?

AkshayMathur92 commented 3 years ago

@AkshayMathur92 they have done this to make sure people abroad do not put load on the api, and also because the vaccination drive is only for Indian people.

Which server or cloud are you facing this issue in?

Apologies my question is not well-formed. I am using Digital ocean droplet, Bangalore region. However, getting a 403 error. My question is what can I do about it ?

ninjabhishek commented 3 years ago

@AkshayMathur92 if you are using node js, you can see @saran-surya comment above on his npm package to bypass this on cloud servers and access the API, if you still want to use digital ocean. if you are not using node js, I would suggest you move your code to Azure, GCP or AWS servers in Indian regions and it would work. I am using combination of python and java and my code are on azure and aws servers

AkshayMathur92 commented 3 years ago

@AkshayMathur92 if you are using node js, you can see @saran-surya comment above on his npm package to bypass this on cloud servers and access the API, if you still want to use digital ocean. if you are not using node js, I would suggest you move your code to Azure, GCP or AWS servers in Indian regions and it would work. I am using combination of python and java and my code are on azure and aws servers

Following up on your advice , I created a server on AWS in both ap-south-1a & ap-south-1b , however both servers were facing the same issue.

ninjabhishek commented 3 years ago

@AkshayMathur92 can you share complete url you are trying to hit?

AkshayMathur92 commented 3 years ago

@AkshayMathur92 can you share complete url you are trying to hit?

I got the issue, I wasn't passing the user agent. Postman automatically adds the user agent by itself, but when you try to get the curl from that , it removes the user agent header.

ninjabhishek commented 3 years ago

@AkshayMathur92 ohh. we faced that too from our azure server in the beginning

rcsrao commented 3 years ago

I am using Google Cloud functions and no luck with user-agent and Mumbai zone.

ninjabhishek commented 3 years ago

same code works on local?

rcsrao commented 3 years ago

Yeah, same working in local and Google cloud VM instance too.

ninjabhishek commented 3 years ago

then cowin does not identify cloud functions ip as Indian origin. code deployed on digitalocean bangalore vm are also facing same issues. you would need to deloy on vm and send requests

rcsrao commented 3 years ago

Yeah, I end up with deploying it in VM

indrajeetgour commented 3 years ago

As we understood, had an issue with the geolocation other than India.

Now I am closing this.