Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zomato api request with python requests library

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?

like image 522
abuzer kadayif Avatar asked Dec 02 '15 09:12

abuzer kadayif


People also ask

Is requests built in library Python?

Requests is one of the most popular Python libraries that is not included with Python.

What is the use of request library in 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).

Is requests native to Python?

Requests is an Apache2 Licensed HTTP library, written in Python, for human beings.


1 Answers

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())
like image 62
vaibhavatul47 Avatar answered Oct 18 '22 01:10

vaibhavatul47