在循环中使用时,Namingm给出错误“101网络不可访问”和“GeocoderUnavailable:服务不可用”

2024-09-27 00:21:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在IBM watson studio中使用jupitor笔记本电脑。 当我对一个地方使用Namingm时,我会像往常一样得到答案,但我有200多个地方的数据库,我想找到这些地方的位置。因此,当我对所有值进行循环时,就会出现上述错误。我已经导入了所有必要的库。 这是准确的密码

for address in amdavad:
       address = '{}, Ahmedabad'.format(amdavad["Borough"])
       geolocator = Nominatim(user_agent="foursquare_agent")
       location = geolocator.geocode(address)
       amdavad['Latitude'] = location.latitude
       amdavad['Longitude'] = location.longitude

这正是我得到的错误

---------------------------------------------------------------------------
timeout                                   Traceback (most recent call last)
/opt/conda/envs/Python36/lib/python3.6/site-packages/geopy/geocoders/base.py in _call_geocoder(self, url, timeout, raw, requester, deserializer, **kwargs)
    343         try:
--> 344             page = requester(req, timeout=timeout, **kwargs)
    345         except Exception as error:

/opt/conda/envs/Python36/lib/python3.6/urllib/request.py in open(self, fullurl, data, timeout)
    525 
--> 526         response = self._open(req, data)
    527 

/opt/conda/envs/Python36/lib/python3.6/urllib/request.py in _open(self, req, data)
    543         result = self._call_chain(self.handle_open, protocol, protocol +
--> 544                                   '_open', req)
    545         if result:

/opt/conda/envs/Python36/lib/python3.6/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    503             func = getattr(handler, meth_name)
--> 504             result = func(*args)
    505             if result is not None:

/opt/conda/envs/Python36/lib/python3.6/urllib/request.py in https_open(self, req)
   1360             return self.do_open(http.client.HTTPSConnection, req,
-> 1361                 context=self._context, check_hostname=self._check_hostname)
   1362 

/opt/conda/envs/Python36/lib/python3.6/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1320                 raise URLError(err)
-> 1321             r = h.getresponse()
   1322         except:

/opt/conda/envs/Python36/lib/python3.6/http/client.py in getresponse(self)
   1330             try:
-> 1331                 response.begin()
   1332             except ConnectionError:

/opt/conda/envs/Python36/lib/python3.6/http/client.py in begin(self)
    296         while True:
--> 297             version, status, reason = self._read_status()
    298             if status != CONTINUE:

/opt/conda/envs/Python36/lib/python3.6/http/client.py in _read_status(self)
    257     def _read_status(self):
--> 258         line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    259         if len(line) > _MAXLINE:

/opt/conda/envs/Python36/lib/python3.6/socket.py in readinto(self, b)
    585             try:
--> 586                 return self._sock.recv_into(b)
    587             except timeout:

/opt/conda/envs/Python36/lib/python3.6/ssl.py in recv_into(self, buffer, nbytes, flags)
   1011                   self.__class__)
-> 1012             return self.read(nbytes, buffer)
   1013         else:

/opt/conda/envs/Python36/lib/python3.6/ssl.py in read(self, len, buffer)
    873         try:
--> 874             return self._sslobj.read(len, buffer)
    875         except SSLError as x:

/opt/conda/envs/Python36/lib/python3.6/ssl.py in read(self, len, buffer)
    630         if buffer is not None:
--> 631             v = self._sslobj.read(len, buffer)
    632         else:

timeout: The read operation timed out

During handling of the above exception, another exception occurred:

GeocoderTimedOut                          Traceback (most recent call last)
<ipython-input-9-cb08644bc039> in <module>
      3 
      4     geolocator = Nominatim(user_agent="foursquare_agent")
----> 5     location = geolocator.geocode(address)
      6     amdavad['Latitude'] = location.latitude
      7     amdavad['Longitude'] = location.longitude

/opt/conda/envs/Python36/lib/python3.6/site-packages/geopy/geocoders/osm.py in geocode(self, query, exactly_one, timeout, limit, addressdetails, language, geometry, extratags)
    307 
    308         return self._parse_json(
--> 309             self._call_geocoder(url, timeout=timeout), exactly_one
    310         )
    311 

/opt/conda/envs/Python36/lib/python3.6/site-packages/geopy/geocoders/base.py in _call_geocoder(self, url, timeout, raw, requester, deserializer, **kwargs)
    369                     raise GeocoderUnavailable('Service not available')
    370             elif isinstance(error, SocketTimeout):
--> 371                 raise GeocoderTimedOut('Service timed out')
    372             elif isinstance(error, SSLError):
    373                 if "timed out" in message:

GeocoderTimedOut: Service timed out

Tags: inpyselfreadlibbuffertimeoutopen

热门问题