backtrackbaba / cowin

Python wrapper for CoWin API's
MIT License
42 stars 18 forks source link

Client error in get availability by pincode #4

Closed AdityaMitra5102 closed 3 years ago

AdityaMitra5102 commented 3 years ago

401 Client Error: Unauthorized for url: https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByPin?pincode=700091&date=04-05-21

Error when get availability by pincode method is run

DragonWarrior15 commented 3 years ago

@AdityaMitra5102, the function call works fine for me. However, when I try the url you have pasted above, it does not work since there is a public missing as part of the url and also the date format should be 04-05-2021 (DD-MM-YYYY). Trying the following in the browser does return the correct result https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode=700091&date=04-05-2021

result (click to expand) ```json { "centers": [{ "center_id": 618896, "name": "BidhanNagar Matri Sadan", "address": "EE 55A, Salt Lake, Kol 700091", "state_name": "West Bengal", "district_name": "North 24 Parganas", "block_name": "Bidhannagar Municipal Corporation", "pincode": 700091, "lat": 22, "long": 88, "from": "09:00:00", "to": "16:00:00", "fee_type": "Free", "sessions": [{ "session_id": "4ad40560-0d02-4a53-a3a1-11cf0a467a7f", "date": "04-05-2021", "available_capacity": 0, "min_age_limit": 45, "vaccine": "COVISHIELD", "slots": ["09:00AM-11:00AM", "11:00AM-01:00PM", "01:00PM-03:00PM", "03:00PM-04:00PM"] }] }, { "center_id": 636345, "name": "BSF Composite Hospital Govt", "address": "SECTOR V AN BLOCK SALTLAKE", "state_name": "West Bengal", "district_name": "North 24 Parganas", "block_name": "Bidhannagar Municipal Corporation", "pincode": 700091, "lat": 22, "long": 88, "from": "09:00:00", "to": "18:00:00", "fee_type": "Free", "sessions": [{ "session_id": "0754a1a5-ebd2-4d69-b699-60a637b452b3", "date": "04-05-2021", "available_capacity": 0, "min_age_limit": 45, "vaccine": "COVISHIELD", "slots": ["09:00AM-11:00AM", "11:00AM-01:00PM", "01:00PM-03:00PM", "03:00PM-06:00PM"] }] }, { "center_id": 620475, "name": "UPHC 8 Samarsarani Kestopur", "address": "Bidhannagar UPHC 8 Ward No. 26 Rajarhat Gopalpur Samarsarani Kestopur", "state_name": "West Bengal", "district_name": "North 24 Parganas", "block_name": "Bidhannagar Municipal Corporation", "pincode": 700091, "lat": 22, "long": 88, "from": "09:00:00", "to": "16:00:00", "fee_type": "Free", "sessions": [{ "session_id": "1bff8fa3-d6bd-4967-854e-ca9410b5d450", "date": "05-05-2021", "available_capacity": 0, "min_age_limit": 45, "vaccine": "COVISHIELD", "slots": ["09:00AM-11:00AM", "11:00AM-01:00PM", "01:00PM-03:00PM", "03:00PM-04:00PM"] }, { "session_id": "fb96eef4-50b4-4476-8f27-6469bc5bbc0d", "date": "06-05-2021", "available_capacity": 0, "min_age_limit": 45, "vaccine": "COVISHIELD", "slots": ["09:00AM-11:00AM", "11:00AM-01:00PM", "01:00PM-03:00PM", "03:00PM-04:00PM"] }] }] } ```

@backtrackbaba, the url is probably incorrect in the constants file and worked for me maybe by chance. The correct url can be found here. Shall I create a pull request to update the line from

    availability_by_pin_code_url = f"{base_url}/appointment/sessions/calendarByPin"

to

    availability_by_pin_code_url = f"{base_url}/appointment/sessions/public/calendarByPin"

?

AdityaMitra5102 commented 3 years ago

Yeah it would be better then

DragonWarrior15 commented 3 years ago

@AdityaMitra5102, I updated my comment above, your date format is also incorrect.. can you try rerunning with the correct date format ?

Tejash-Shah commented 3 years ago

Hi @DragonWarrior15, great work on finding the bug. Please go ahead and create a PR. I found the solution to the same issue from your comment. Thanks!