Zomato which is one of the most popular restaurant search engines provides free api service...
If curl is used in api request, works perfectly;
curl -X GET --header "Accept: application/json" --header "user_key: MY_API_KEY_HERE" "https://developers.zomato.com/api/v2.1/geocode?lat=41.10867962215988&lon=29.01834726333618"
But Python's requests
library is used, it doesn't work. When I execute the code below;
import requests
r = requests.get("https://developers.zomato.com/api/v2.1/geocode?lat=41.10867962215988&lon=29.01834726333618", headers={"user_key": "MY_API_KEY_HERE", "Accept": "application/json"});
interpreter returns the error below;
requests.exceptions.ProxyError: Cannot connect to proxy. Socket error: Tunnel connection failed: 403 Forbidden.
Several attempts made via pyCurl
library but unfortunately result is the same; 403 Forbidden
How can I tackle this issue?
Requests is one of the most popular Python libraries that is not included with Python.
The requests module allows you to send HTTP requests using Python. The HTTP request returns a Response Object with all the response data (content, encoding, status, etc).
Requests is an Apache2 Licensed HTTP library, written in Python, for human beings.
I also had problems using Zomato API's. I was getting 500 Server Error
Adding User Agent
info in headers solved my problem.
import requests
from pprint import pprint
locationUrlFromLatLong = "https://developers.zomato.com/api/v2.1/cities?lat=28&lon=77"
header = {"User-agent": "curl/7.43.0", "Accept": "application/json", "user_key": "YOUR_API_USER_KEY"}
response = requests.get(locationUrlFromLatLong, headers=header)
pprint(response.json())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With