目标计算机拒绝连接

时间:2017-06-06 18:50:06

标签: python-3.x geopy nominatim

from geopy.geocoders import Nominatim
import openpyxl
wb = openpyxl.load_workbook('#######.xlsx')
ws = wb.active
geolocator = Nominatim(timeout=60)

for i in range(2,1810):
    count1 = 0
    count2 = 1
    address = str(ws['B'+str(i)].value)
    city = str(ws['C'+str(i)].value)
    state = str(ws['D'+str(i)].value)
    zipc = str(ws['F'+str(i)].value)
    result = None
    iden1 = address + ' ' + city + ' ' + state
    iden2 = city + ' ' + zipc + ' ' + state
    iden3 = city + ' ' + state
    print(iden1, iden2, iden3)
    print(geolocator.geocode(iden2).address)
    try:
        location1 = geolocator.geocode(iden1)
    except:
        pass
    try:
        location2 = geolocator.geocode(iden2)
    except:
        pass
    try:
        location3 = geolocator.geocode(iden3)
    except:
        pass
    count = None
    try:
        county1 = str(location1.address)
        county1_list = county1.split(", ")
        #print(county1_list)
        for q in county1_list:
            if 'county' in q.lower():
                if count == None:
                    count = q
    except:
        pass
    try:
        county2 = str(location2.address)
        county2_list = county2.split(", ")
        #print(county2_list)
        for z in county2_list:
            if 'county' in z.lower():
                if count == None:
                    count = z
    except:
        pass
    try:
        county3 = str(location3.address)
        county3_list = county3.split(", ")
        #print(county3_list)
        for j in county3_list:
            if 'county' in j.lower():
                if count == None:
                    count = j
    except:
        pass
    print(i, count)
    #ws['E'+str(i)] = count
    if count == 50:
        #wb.save("#####" +str(count2) +".xlsx")
        count2 += 1
        count1 = 0

from geopy.geocoders import Nominatim import openpyxl wb = openpyxl.load_workbook('#######.xlsx') ws = wb.active geolocator = Nominatim(timeout=60) for i in range(2,1810): count1 = 0 count2 = 1 address = str(ws['B'+str(i)].value) city = str(ws['C'+str(i)].value) state = str(ws['D'+str(i)].value) zipc = str(ws['F'+str(i)].value) result = None iden1 = address + ' ' + city + ' ' + state iden2 = city + ' ' + zipc + ' ' + state iden3 = city + ' ' + state print(iden1, iden2, iden3) print(geolocator.geocode(iden2).address) try: location1 = geolocator.geocode(iden1) except: pass try: location2 = geolocator.geocode(iden2) except: pass try: location3 = geolocator.geocode(iden3) except: pass count = None try: county1 = str(location1.address) county1_list = county1.split(", ") #print(county1_list) for q in county1_list: if 'county' in q.lower(): if count == None: count = q except: pass try: county2 = str(location2.address) county2_list = county2.split(", ") #print(county2_list) for z in county2_list: if 'county' in z.lower(): if count == None: count = z except: pass try: county3 = str(location3.address) county3_list = county3.split(", ") #print(county3_list) for j in county3_list: if 'county' in j.lower(): if count == None: count = j except: pass print(i, count) #ws['E'+str(i)] = count if count == 50: #wb.save("#####" +str(count2) +".xlsx") count2 += 1 count1 = 0

大家好,这段代码非常简单,并使用geopy来提取县名,使用3种不同的方法名称iden1,iden2和iden3,它们是地址,城市,州和邮政编码的组合。这种方式可以运行大约300行但是开始重复同一个县,并且在重新启动脚本之后,只是吐出Nones。我放入行打印(geolocator.geocode(iden2).address)来查找错误并收到此错误消息。

追踪(最近一次呼叫最后一次):

  

文件“C:/ Users / ##### / Downloads / Web content / ##### / #### _ county.py”,   第19行,在       print(geolocator.geocode(iden2).address)文件“C:\ Users ##### \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ geopy \ geocoders \ osm.py”,   第193行,在地理编码中       self._call_geocoder(url,timeout = timeout),exact_one文件“C:\ Users ##### \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ geopy \ geocoders \ base.py” ,   第171行,在_call_geocoder中       raise GeocoderServiceError(message)geopy.exc.GeocoderServiceError:[WinError 10061]没有连接可以   是因为目标机器主动拒绝它

此脚本之前正在运行,但现在没有。我的IP是否被阻止使用goepy的数据库或其他东西?谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

看起来你正在限制他们的利率。他们似乎要求您将API请求限制为1 /秒。您可以查看here的使用政策,其中列出了使用其API和附件的替代方法。