使用 Python 2.6,当我运行下面的脚本时会发生以下错误:
Traceback (most recent call last):
File "g.py", line 7, in <module>
results = Geocoder.geocode(row[0])
File "/usr/lib/python2.6/site-packages/pygeocoder.py", line 261, in geocode
return GeocoderResult(Geocoder.getdata(params=params))
File "/usr/lib/python2.6/site-packages/pygeocoder.py", line 223, in getdata
raise GeocoderError(j['status'], url)
pygeocoder.GeocoderError: Error ZERO_RESULTS
Query: http://maps.google.com/maps/api/geocode/json?region=&sensor=false&bounds=&language=&address=%22++A+FAKE+ADDRESS
Python 2.6 脚本:
import csv, string
from pygeocoder import Geocoder
with open('file.csv') as goingGeo:
theSpreadsheet = csv.reader(goingGeo, quotechar=None)
for row in theSpreadsheet:
results = Geocoder.geocode(row[0])
(lat, long) = results[0].coordinates
with open('geo_file.csv', 'a') as f:
f.write(row[0] + ",")
f.write(row[1] + ",")
f.write(row[2] + ",")
f.write(row[3] + ",")
f.write(row[4] + ",")
f.write(row[5] + ",")
f.write(row[6] + ",")
f.write(row[7] + ",")
try:
f.write(str(lat))
except GeocoderError:
pass
f.write(",")
try:
f.write(str(long))
except GeocoderError:
pass
f.write('\n')
我只希望脚本即使出现错误也能继续。
谢谢!