无法使用正确的pagetoken查询参数正确表达rest请求

2024-04-25 19:40:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我提出以下休息要求:

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客户机上运行良好,这让我相信im没有正确编码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

请帮助正确的编码方式,如果这是我所犯的错误


Tags: httpstokenjsonfalseurldatarequestpage