5

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?

kgandroid
  • 5,507
  • 5
  • 39
  • 69

1 Answers1

8

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())
vaibhavatul47
  • 2,766
  • 4
  • 29
  • 42