abu*_*yif 5 python json pycurl python-requests zomato-api
Zomato是最受欢迎的餐厅搜索引擎之一,提供免费的api服务......
如果在api请求中使用curl,则效果很好;
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"
Run Code Online (Sandbox Code Playgroud)
但是使用Python的requests库,它不起作用.当我执行下面的代码时;
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"});
Run Code Online (Sandbox Code Playgroud)
解释器返回以下错误;
requests.exceptions.ProxyError: Cannot connect to proxy. Socket error: Tunnel connection failed: 403 Forbidden.
Run Code Online (Sandbox Code Playgroud)
通过pyCurl库进行了几次尝试但不幸的结果是相同的;403 Forbidden
我该如何解决这个问题?
我在使用Zomato API时也遇到了问题.我得到了500 Server Error
User Agent在标题中添加信息解决了我的问题.
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())
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2765 次 |
| 最近记录: |