handyfreak / python-weather-api

Automatically exported from code.google.com/p/python-weather-api
MIT License
0 stars 0 forks source link

google weather api should escape location id #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Google's API will accept locations with spaces (e.g. "London, England" instead 
of 
"London,England"). If you try this, you get:

>>> pywapi.get_weather_from_google('london, england')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pywapi.py", line 51, in get_weather_from_google
    handler = urllib2.urlopen(url)
  File "/usr/lib/python2.5/urllib2.py", line 124, in urlopen
    return _opener.open(url, data)
  File "/usr/lib/python2.5/urllib2.py", line 387, in open
    response = meth(req, response)
  File "/usr/lib/python2.5/urllib2.py", line 498, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.5/urllib2.py", line 425, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.5/urllib2.py", line 506, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request

If you cal urllib.quote on the location_id before generating the URL, then it 
fixes it.

Original issue reported on code.google.com by dan.y.t...@gmail.com on 25 Aug 2009 at 6:09

GoogleCodeExporter commented 9 years ago
Thank you! The issue was fixed in r103 commit.

Original comment by qet...@gmail.com on 25 Aug 2009 at 9:29

GoogleCodeExporter commented 9 years ago

Original comment by qet...@gmail.com on 25 Sep 2009 at 9:08