pygeolib.GeocoderError:错误ZERO_RESULTS

时间:2015-09-09 07:33:17

标签: python geocoding

使用案例:我正在尝试使用python地理编码程序包提取我从网站收集的地址的经纬度和经度。

问题:每当我执行给定的代码时,我都会一直得到GeoCodeError。

xlSheet.Range("A7:H7").Copy()
xlSheet.Range("A%s:H%s"%(r,r)).PasteSpecial(Paste=-4122)

我搜索了SO以寻找任何可能的解决方案,我得到的最接近的是here但是即使我从地址中删除了Zip代码,我仍然会收到相同的错误消息。

代码如下

Traceback (most recent call last):
File "C:/Users/Ashish/PycharmProjects/Petrogeocode.py", line 13, in  <module>
address=Geocoder.geocode(addr)
File "C:\Users\Ashish\AppData\Roaming\Python\Python27\site- packages\pygeocoder.py", line 129, in geocode
return GeocoderResult(Geocoder.get_data(params=params))
File "C:\Users\Ashish\AppData\Roaming\Python\Python27\site-  packages\pygeocoder.py", line 212, in get_data
raise GeocoderError(response_json['status'], response.url)
pygeolib.GeocoderError: Error ZERO_RESULTS
Query: https://maps.google.com/maps/api/geocode/json?language=&region=&bounds=&components=&address=lot+1190%2C+mukim+bukit+tinggi+kepala+batas&sensor=false

Process finished with exit code 1

sample.txt文件的地址如下所示

__author__ = 'Ashish'

from pygeocoder import Geocoder
from pygeolib import GeocoderError

bad_addr=open('bad_addr.txt','w') 
good_addr=open('good_addr.txt','w')

with open('sample.txt') as f:
addrlist=f.read().splitlines()

for addr in addrlist:
    address=Geocoder.geocode(addr) # read the first address in the list

    try:
        address=Geocoder.geocode(' '.join(addr)) # try to geocode it

        if not address.valid_address:
            bad_addr.write(str(address)) # if the address is not valid then write it to a file called bad_addr.txt
            bad_addr.write(str(address.coordinates)) # Also write the coordinates if found
            bad_addr.write("\n")
        else:
            good_addr.write(str(address)) # if the address is valid then write it to a file called good_addr.txt
            good_addr.write(str(address.coordinates))
            good_addr.write("\n")
         #   continue
    except GeocoderError:
        print "The address: ",addr," could not be geocoded" # catch the bad address exception thrown 


bad_addr.close() # close the file
good_addr.close() # close the file
f.close() 

请建议我在代码中可以做些什么来解决这个问题。 谢谢

2 个答案:

答案 0 :(得分:0)

从其他来源尝试API。 Geocoder无法识别您的地址。

答案 1 :(得分:-1)

对于可能遇到未被捕获的异常问题的任何人,请确保已从pygeolib导入Geocoder对象。我在排除故障时错过了。

from pygeolib import GeocoderError