我已按照http://code.google.com/p/geopy/wiki/GettingStarted中的教程进行操作, 效果很好:
g = geocoders.Google(resource='maps')
我想使用 json 作为输出格式,因为我想在 javascript 中处理结果。
但每次我使用:
g = geocoders.Google(resource='maps', output_format='json')
我收到以下错误:
Environment:
Request Method: GET
Request URL: http://localhost:8000/business/view/13/
Django Version: 1.2.1
Python Version: 2.5.1
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'registration',
'pley.business',
'pley.review',
'django.contrib.admin',
'django.contrib.webdesign']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "C:\Python25\Lib\site-packages\django\core\handlers\base.py" in get_response
100. response = callback(request, *callback_args, **callback_kwargs)
File "C:\django\pley\..\pley\business\views.py" in business_view
57. for place, (lat, lng) in g.geocode(string_location,exactly_one=False):
File "c:\python25\lib\site-packages\geopy-0.94-py2.5.egg\geopy\geocoders\google.py" in geocode
66. return self.geocode_url(url, exactly_one)
File "c:\python25\lib\site-packages\geopy-0.94-py2.5.egg\geopy\geocoders\google.py" in geocode_url
73. return dispatch(page, exactly_one)
File "c:\python25\lib\site-packages\geopy-0.94-py2.5.egg\geopy\geocoders\google.py" in parse_json
123. json = simplejson.loads(page)
File "C:\Python25\lib\site-packages\simplejson-2.1.1-py2.5-win32.egg\simplejson\__init__.py" in loads
384. return _default_decoder.decode(s)
File "C:\Python25\lib\site-packages\simplejson-2.1.1-py2.5-win32.egg\simplejson\decoder.py" in decode
402. obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python25\lib\site-packages\simplejson-2.1.1-py2.5-win32.egg\simplejson\decoder.py" in raw_decode
420. raise JSONDecodeError("No JSON object could be decoded", s, idx)
Exception Type: JSONDecodeError at /business/view/13/
Exception Value: No JSON object could be decoded: line 1 column 0 (char 0)
任何建议/回复将不胜感激。
谢谢!