python - 从 Geopy 库中获取纬度和经度时出错
问题描述
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="main")
location = geolocator.geocode({"postalcode": 333031})
print(location.raw)
回溯(最后一次调用):文件“/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/urllib/request.py”,第 1319 行,在 do_open h.request (req.get_method()、req.selector、req.data、标头、文件“/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client.py” ,第 1245 行,在请求 self._send_request(method, url, body, headers, encode_chunked) 文件“/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client .py”,第 1291 行,在 _send_request self.endheaders(body, encode_chunked=encode_chunked) 文件“/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client. py",第 1240 行,在 endheaders 中。_send_output(message_body, encode_chunked=encode_chunked) 文件“/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client.py”,第 1008 行,在 _send_output self.send (味精)文件“/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client.py”,第948行,在发送self.connect()文件“/ Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client.py",第 1414 行,在 connect self.sock = self._context.wrap_socket(self.sock,文件“/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ssl.py”,第 500 行,在 wrap_socket return self.sslsocket_class._create(File"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ssl.py”,第 1040 行,在 _create self.do_handshake() 文件“/Library/Developer/CommandLineTools/Library /Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ssl.py”,第 1309 行,在 do_handshake self._sslobj.do_handshake() socket.timeout: _ssl.c:1091: 握手操作超时
在处理上述异常的过程中,又出现了一个异常:
Traceback(最近一次调用最后一次):文件“/Users/temp/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/geopy/adapters.py”,第 297 行,在 get_text page = self.urlopen(req ,超时=超时)文件“/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/urllib/request.py”,第525行,打开响应= self._open(请求,数据)文件“/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/urllib/request.py”,第 542 行,在 _open 结果 = self._call_chain(self .handle_open,协议,协议 + 文件“/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/urllib/request.py”,第 502 行,在 _call_chain 结果 = func( *args) 文件 "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/urllib/request.py”,第 1362 行,在 https_open 返回 self.do_open(http.client.HTTPSConnection, req, do_open 中的文件“/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/urllib/request.py”,第 1322 行引发 URLError(err) urllib.error.URLError:
在处理上述异常的过程中,又出现了一个异常:
回溯(最后一次调用):文件“/Users/temp/PycharmProjects/pythonProject/main.py”,第 8 行,位置 = geolocator.geocode({"postalcode": 152116}) 文件“/Users/temp/PycharmProjects /pythonProject/venv/lib/python3.8/site-packages/geopy/geocoders/nominatim.py”,第 297 行,在地理编码中返回 self._call_geocoder(url, callback, timeout=timeout) 文件“/Users/temp/PycharmProjects /pythonProject/venv/lib/python3.8/site-packages/geopy/geocoders/base.py”,第 368 行,在 _call_geocoder 结果 = self.adapter.get_json(url, timeout=timeout, headers=req_headers) 文件“/ Users/temp/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/geopy/adapters.py",第 286 行,在 get_json 文本 = self.get_text(url, timeout=timeout, headers=headers) 文件中"/Users/temp/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/geopy/adapters.py”,第 315 行,在 get_text 中引发 GeocoderTimedOut(“服务超时”) geopy.exc.GeocoderTimedOut:服务定时出去
解决方案
推荐阅读
- django - 带括号的Django ForeignKey:模型无法解析
- react-native - 我可以将来自 aws-amplify-react-native 的错误消息对齐为中心吗
- amazon-s3 - 列出具有特定名称标签的 s3 文件夹
- php - 根据用户角色创建单独的表
- python - Python pandas - 按组有效地将函数应用于缺少日期的滚动窗口
- javascript - 删除多个电子表格中的多个工作表
- javascript - 三.js 移动触摸允许身体滚动
- c++ - 错误:请求“b”中的成员“q”,它是非类类型“const int”
- artifactory - Artifactory 7.2.1 - 如何更改 Artifactory 和 UI 的监听地址
- javascript - 并排的带有水平滚动条的代码框?