Invalid request from Yelp API

Inspired by this Yelp tutorial , I created a script to find all the gyms in a given city. I updated the script with these updates to return ALL gyms, not just the first 20. You can find a gist. SEARCH_LIMIT - 20.

I encountered a Bad Request error. I followed the Yelp Tutorial tutorial closely and am not sure if it can come - I am sure that the request is correctly encoded and all my API keys are correct.

Printout below:

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 
+6
source share
2 answers

In the examples of search parameters, they replace spaces with a + sign:

 'term': term.replace(' ', '+'), 'location': location.replace(' ', '+'), 

In your essence, you have a hard-coded location like: 'New York, NY' , changing spaces to + should help.

+1
source

The Yelp API has limitations. You can get a maximum of 20 items for each request. In addition, the number of items available is 1000. I cannot find information about the limitations on the documentation . But I found information about these limitations in the support group. Based on this, you can get a maximum of 1000 elements for 50 queries ([1, ..., 20], [21, ..., 40], ... [981, ..., 1000])

As for your fragment, you are trying to get more than 1000 items. I found out that your options are constraints and offsets. limit = 3, offset = 1000 . This means that you want to receive items from 1001 to 1003. And this is contrary to the documentation.

HTTP Error 400: Bad Request means you get a response

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

If you open your last signed_url in a browser, you will see the answer as above. You will also see a 400 Bad Request response status code.

+1
source

All Articles