Geopy:OSError:[Errno 101]网络无法访问

时间:2018-10-16 08:27:17

标签: python geocoding geopy

我正在使用Geopy库将英语名称位置列表转换为纬度和经度。但是,在执行过程中,程序引发了错误:OSError: [Errno 101] Network is unreachable。我想知道是否与我的代码有关,或者仅仅是网络错误?

我的代码:

from geopy.geocoders import Nominatim
import pandas as pd


df = pd.read_csv('/*****.csv')

for cell in df['Offices']:
    cell = pinyin.get(cell, format="strip", delimiter='')
    place = str(cell)
    geolocator = Nominatim(timeout=3)
    location = geolocator.geocode(place)
    print(location)
    if location:
        print((location.latitude, location.longitude))
print('Converting finished.')

完整异常如下:

Traceback (most recent call last):
  File "/usr/lib/python3.6/urllib/request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/usr/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/usr/lib/python3.6/http/client.py", line 1392, in connect
    super().connect()
  File "/usr/lib/python3.6/http/client.py", line 936, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/lib/python3.6/socket.py", line 724, in create_connection
    raise err
  File "/usr/lib/python3.6/socket.py", line 713, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network is unreachable

0 个答案:

没有答案