Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API is unable to fetch data by pincode #20

Open
babvin opened this issue May 11, 2021 · 3 comments
Open

API is unable to fetch data by pincode #20

babvin opened this issue May 11, 2021 · 3 comments

Comments

@babvin
Copy link

babvin commented May 11, 2021

from cowin_api import CoWinAPI

pin_code = ["570021","560066"]
date = '03-05-2021' # Optional. Default value is today's date
min_age_limit = 18 # Optional. By default returns centers without filtering by min_age_limit
for pin in pin_code:
cowin = CoWinAPI()
print(pin, type(pin))
try:
available_centers = cowin.get_availability_by_pincode(pin_code, date, min_age_limit)
print(available_centers)
except Exception as Error:
print("Error for pin,", pin, Error)

570021 <class 'str'>
Error for pin, 570021 'HTTPError' object has no attribute 'get'
560066 <class 'str'>
Error for pin, 560066 'HTTPError' object has no attribute 'get'

@backtrackbaba
Copy link
Owner

Hi @babvin, this is a general issue with CoWin where it throws a 401 error at times. I ran the sample you provided and was able to execute it successfully.

For now, try to retry in case you get an Exception. There is an open PR #16 which will be merged soon and would give you an option to retry automatically.

Also, the exception handling in the library is not too good currently. We are working on it and would be releasing a v1.0.0 with the updated breaking changes which would also address the exceptions being raised.

@clatonhendricks
Copy link

I've noticed this error when you try to fetch data outside of India, I have to use a VPN to go around it. I've added try-exception block to get around the issue and provide an useful msg to the user. Would appreciate if exception is thron from the API.

@backtrackbaba
Copy link
Owner

Hi @clatonhendricks, there's a geofencing enabled by the CoWin team which forces you to use Indian IPs to fetch the data.

About the useful error message, apologies for the issue, that's an oversight/mistake from my end which I've fixed in the latest code on master. This will propagate the exceptions thrown by the requests library based on which you can handle. I'll be deploying it to PyPi today as v1.0 as it has some breaking changes.

I'll notify here as soon as it is pushed to PyPi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants