我提出了以下休息请求:
https://maps.googleapis.com/maps/api/place/textsearch/json?fields=types%2Cphotos%2Cformatted_address%2Cname%2Cpermanently_closed%2Copening_hours%2Crating%2Cuser_ratings_total%2Cplus_code&pagetoken=CrQCJAEAAGy5SDC_hwcBg_plNe50Q_tMu1aCllTBrRIJy9m2DkxFVGXNLDD3bz23kG7q1dlFSdlFgaKowMPyLP7ecoL3-qaATut7dw4ebP_zz1cVQh0uCZI4DxiQablPO2HVTe8AApfOtx258YyoV6N1liqxcrgv60YaEYCXVaOrG7uO0hh2ew1_831QWsondLKQLAH87GnqFIx456Z6-rXObuDCSpAK50LLFHroCJvWCyHg7uPnOK0QlWl0hEOwFCuGUSFIjAgrpr8XDcRSxwOkm_hr908I9JH9DWXGMCOc5v67OlVKAcHDumVifD9mUFYQrt6wWoaObUqnMcndN5nf_9gAmr3iVoiGxJPLWK2Ehb2SNqpIFqZCym1exBCpTrrySfYx_WBKwT68HbSAbI9052fiPpQSEGbnTS49qkXz3_Xn0eT0GoUaFEQ0qpquGT1LktIwybA4nXqOnw2P&location=13.026232%2C77.502529&key=MYKEY&input=car+service&inputtype=textquery
并获得以下响应:
{u'status': u'INVALID_REQUEST', u'html_attributions': [], u'results': []}
当我不提供 pagetoken 查询参数时,相同的请求有效,但是当我尝试使用此参数获取下一页时,遇到了上述问题。
分页在POSTMAN rest客户端上正常工作,这使我相信我无法正确编码url。
while same_request:
r = requests.get(url = URL, params = PARAMS)
print r.request.url
print r.request.headers
print r.json()
# extracting data in json format
data = r.json()
next_page_token = parse_results(data, False)
print "recieved token>>>", next_page_token
if next_page_token:
same_request = True
PARAMS['pagetoken'] = quote(next_page_token)
else:
same_request = False
如果确实存在错误,请提供正确的编码方法。
答案 0 :(得分:0)
Google要求在随后的请求之间短暂暂停。睡2秒钟就能解决问题