【问题标题】:Raise Respond not ready in python在python中引发响应未准备好
【发布时间】:2019-12-01 21:50:32
【问题描述】:

python 实例在运行后引发 ResponseNot ready 错误

import httplib2
import json


def getGeocodeLocation(inputString):
    google_api_key = "AIzaSyCluVT5yELlVqmZEdOrBRub3CkKzFfVobw"
    locationString = inputString.replace(" ", "+")
    url = ('https://maps.googleapis.com/maps/api/ \
           geocode/json?address=%s&key=%s' % (locationString, google_api_key))
    h=httplib2.Http()
    (response, content) = h.request(url,'GET')
    result = json.loads(content)

    print "response header: %s\n \n" % result
    return result

引发的错误是

Traceback (most recent call last):   File "<stdin>", line 1, in <module>   File "geocode.py", line 11, in getGeocodeLocation
    (response, content) = h.request(url,'GET')   File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 2135, in request
    cachekey,   File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1796, in _request
    conn, request_uri, method, body, headers   File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1737, in _conn_request
    response = conn.getresponse()   File "/usr/lib/python2.7/httplib.py", line 1139, in getresponse
    raise ResponseNotReady() httplib.ResponseNotReady

我不知道出了什么问题

【问题讨论】:

  • 检查print(url) - 如果你把它分成两行那么你的url中有空格。

标签: python api httplib2


【解决方案1】:

你必须把网址放在一行

url = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s&key=%s' % (locationString, google_api_key)

分成两行,它添加到这些行中的 url 空间 - 请参阅 print(url)

https://maps.googleapis.com/maps/api/            geocode/json?address=a&key=AIzaSyCluVT5yELlVqmZEdOrBRub3CkKzFfVobw

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 2019-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多