Yelp API的错误请求 [英] Bad Request from Yelp API

查看:112
本文介绍了Yelp API的错误请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此Yelp教程的启发,我创建了一个脚本搜索给定城市中的所有体育馆.我使用这些更新调整了脚本,以便返回所有健身房,而不仅仅是前20个.您可以找到要点此处. SEARCH_LIMIT为20.

Inspired by this Yelp tutorial, I created a script to search for all gyms in a given city. I tweaked the script with these updates in order to return ALL gyms, not just the first 20. You can find the gist here. The SEARCH_LIMIT is 20.

我遇到了错误的请求错误.我非常仔细地遵循了Yelp教程,并且不确定它来自何处-我很确定请求已正确编码,并且我所有的API密钥都是正确的.

I'm encountering a Bad Request error. I followed the Yelp Tutorial pretty closely, and am unsure of what it can be coming from -- I'm pretty sure the request is properly encoded, and all my API keys are right.

打印输出如下:

Traceback (most recent call last):
  File "YelpSearch.py", line 97, in <module>
    query_api()
  File "YelpSearch.py", line 74, in query_api
    response = search_yelp(offset) 
  File "YelpSearch.py", line 67, in search_yelp
    return request(API_HOST, SEARCH_PATH, url_params=url_params)
  File "YelpSearch.py", line 53, in request
    conn = urllib2.urlopen(signed_url, None)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 410, in open
    response = meth(req, response)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 523, in http_response
    'http', request, response, code, msg, hdrs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 448, in error
    return self._call_chain(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 531, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request

推荐答案

Yelp API有局限性.每个请求最多可以获取20个项目.此外,可访问项目的数量为1000.我找不到有关文档.但是,我在支持组中找到了有关这些限制的信息.基于此,您最多可以获取50个请求([1,...,20],[21,...,40],... [981,...,1000])中的1000个项目

Yelp API has limitations. You can get maximum 20 items for each request. Also, quantity of accessible items is 1000. I can't find information about limitations on the documentation. But, I found info about these limitations on the support group. Based on this you can get maximum 1000 items for 50 requests([1,..., 20], [21,..., 40], ... [981,..., 1000] )

关于您的代码段,您尝试获取1000多个项目.我发现您的极限和偏移量参数. limit = 3, offset = 1000.这意味着您要获取1001到1003之间的商品.这与文档相矛盾.

Regarding your snippet you are trying get more than 1000 items. I found out that your limit and offset parameters. limit = 3, offset = 1000. It means you want to get items from 1001 to 1003. And it contradicts the documentation.

HTTP Error 400: Bad Request表示您得到响应

{
  error: {
    field: "offset",
    description: "The maximum number of accessible results is 1000",
    id: "INVALID_PARAMETER",
    text: "One or more parameters are invalid in request"
  }
}

如果在浏览器上打开最后一个signed_url,您将看到如上的响应.另外,您将看到响应状态代码为400 Bad Request.

If you open your last signed_url on the browser you will see response like above. Also, you will see Response Status Code is 400 Bad Request.

这篇关于Yelp API的错误请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆