Raise Respond not ready in python

269 views Asked by At

The python instance is raising ResponseNot ready error after running

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

the error raised is

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

and i can't figure out what's wrong

1

There are 1 answers

0
furas On

You have to put url in one line

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

Splitting into two lines it adds to url spaces which are in these lines - see print(url)

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