本文介绍了如何使谷歌地图python库检测SSL证书?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 开始工作: import googlemaps gmaps = googlemaps.Client(key ='AIza ...')#对地址进行地理编码 geocode_result = gmaps.geocode('1600 Amphitheatre Parkway,Mountain CA') 到目前为止试过... 我修正了所有请求库相关问题: >>>请求.__ version__ '2.9.1' 我通过pip安装了请求。 p> 另外我试图通过尝试另一个案例来揭露问题: import请求导入certifi r = requests.get('https://graph.facebook.com/spotify',verify = certifi.where())r = requests.get ('https://graph.facebook.com/spotify') 所有作品没有任何问题。 然后: openssl s_client -connect graph.facebook.com :443 -CAfile $(python -m certifi) 无任何问题。 但是: $ b $ pre $ import googlemaps gmaps = googlemaps.Client(key = 'AIza ...')#对地址进行地理编码 geocode_result = gmaps.geocode('1600 Amphitheatre Parkway,Mountain View,CA') 返回: 追踪(最近一次致电las t):文件get_times.py,第7行,位于< module> geocode_result = gmaps.geocode('1600 Amphitheatre Parkway,Mountain View,CA')文件/usr/local/lib/python2.7/dist-packages/googlemaps/geocoding.py,行68,地理编码返回client._get(/ maps / api / geocode / json,params)[results] 文件/usr/local/lib/python2.7/dist- ('SSL例程',''),第205行,在_get 中加载了packages / googlemaps / client.py SSL3_GET_SERVER_CERTIFICATE','证书验证失败')],) 有点奇怪 - (我剪出长的十六进制代码): $ openssl s_client -connect maps.googleapis.com:443 -CAfile CONNECTED(00000003) depth = 3 C = US,O = Equifax,OU = Equifax安全认证中心验证返回:1 深度= 2 C = US,O = GeoTrust Inc.,CN = GeoTrust Global CA 验证退货:1 depth = 1 C = US,O = Google Inc,CN = Google互联网管理局G2 验证回报:1 深度= 0 C =美国,ST =加利福尼亚州,L =山景城, O = Google Inc,CN = * .googleapis.com 验证退货:1 --- 证书链 0 s:/ C = US / ST = California / L = Mountain View / O = Google Inc / CN = *。googleapis.com i:/ C = US / O = Google Inc / CN = Google互联网管理局G2 1 s:/ C = US / O = Google Inc / CN = Google互联网管理局G2 i:/ C = US / O = GeoTrust Inc./CN=GeoTrust Global CA 2 s:/ C = US / O = GeoTrust Inc./CN = GeoTrust Global CA i:/ C = US / O = Equifax / OU = Equifax安全认证中心 --- 服务器证书 ----- BEGIN CERTIFICATE-- --- ... ----- END CERTIFICATE ----- subject = / C = US / ST = California / L = Mountain View / O = Google Inc /CN=*.googleapis.com issuer = / C = US / O = Google Inc / CN = Google互联网管理局G2 --- 没有客户证书CA名称已发送 --- SSL握手已读取3820字节并写入431字节 --- 新的TLSv1 / SSLv3密码为ECDHE-RSA-AES128-GCM-SHA256 服务器公钥为2048位支持安全重协商压缩:NONE 扩展:NONE SSL-Session:协议:TLSv1.2 密码:ECDHE-RSA-AES128-GCM-SHA256 会话ID:... 会话ID- ctx: Master-Key:... Key-Arg:无 PSK身份:无 PSK身份提示:无 SRP用户名:无 TLS会话票寿命提示:100800(秒) TLS会话票: 0000 - ...。 开始时间:1454060879 超时: 300(秒)验证返回码:0(好) --- 导入请求导入certifi API_KEY =AIza ... url =(https://maps.googleapis.com/maps/api/directions/json?origin = 75 + 9 th + Ave + New + York,+ NY&目的地= MetLife + Stadium + 1 + MetLife + Stadium + Dr + East + Rutherford,+ NJ + 07073&key =%s )%(API_KEY)r = requests.get(url,verify = certifi.where()) $ b $结果是: $ b $ pre $ Traceback(最近一次调用最后一次):文件get_times.py ,第10行,在< module> r = requests.get(url,verify = certifi.where())文件/usr/local/lib/python2.7/dist-packages/requests/api.py,第67行,获取返回请求('get',url,params = params,** kwargs)文件/usr/local/lib/python2.7/dist-packages/requests/api.py第53行,请求 return session.request(method = method,url = url,** kwargs)文件/usr/local/lib/python2.7/dist-packages/requests/ sessions.py,第468行,请求 resp = self.send(prep,** send_kwargs)文件/usr/local/lib/python2.7/dist-packages/requests/sessions .py,第576行,发送r = adapter.send(request,** kwargs)文件/usr/local/lib/python2.7/dist-packages/requests/adapters.py ,第447行,发送 SSLError(e,request = request) requests.exceptions.SSLError:错误握手:错误([('SSL例程','SSL3_GET_SERVER_CERTIFICATE','证书验证失败')],) 我没有在任何服务器上运行这个或托管...我只是想让它在我的电脑上作为一个简单的CLI脚本工作... 解决方案感谢Liam Horne在这里的答案: https://stackoverflow.com/a/34665344/552621 我找到了一个解决方案。在运行的 certifi 版本中似乎存在一个主要问题。我从这个(非常长的) GitHub问题中发现: https:/ /github.com/certifi/python-certifi/issues/26 TL; DR pip uninstall -y certifi&& pip install certifi == 2015.04.28 The problemMake to work:import googlemaps gmaps = googlemaps.Client(key='AIza...') # Geocoding an address geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')Tried so far ...I fixed all requests library relevant issues:>>> requests.__version__'2.9.1'I have requests installed through pip.Also I tried to expose the problem by trying another case:import requestsimport certifir = requests.get('https://graph.facebook.com/spotify', verify=certifi.where())r = requests.get('https://graph.facebook.com/spotify')All works without any problems.Then:openssl s_client -connect graph.facebook.com:443 -CAfile $(python -m certifi)Works without any problem.But:import googlemapsgmaps = googlemaps.Client(key='AIza...')# Geocoding an addressgeocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')Returns:Traceback (most recent call last): File "get_times.py", line 7, in <module> geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA') File "/usr/local/lib/python2.7/dist-packages/googlemaps/geocoding.py", line 68, in geocode return client._get("/maps/api/geocode/json", params)["results"] File "/usr/local/lib/python2.7/dist-packages/googlemaps/client.py", line 205, in _get raise googlemaps.exceptions.TransportError(e)googlemaps.exceptions.TransportError: bad handshake: Error([('SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed')],)What's double weird - it seems to work this way (I cut out the long hex-codes):$ openssl s_client -connect maps.googleapis.com:443 -CAfile $(python -m certifi)CONNECTED(00000003)depth=3 C = US, O = Equifax, OU = Equifax Secure Certificate Authorityverify return:1depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CAverify return:1depth=1 C = US, O = Google Inc, CN = Google Internet Authority G2verify return:1depth=0 C = US, ST = California, L = Mountain View, O = Google Inc, CN = *.googleapis.comverify return:1---Certificate chain 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=*.googleapis.com i:/C=US/O=Google Inc/CN=Google Internet Authority G2 1 s:/C=US/O=Google Inc/CN=Google Internet Authority G2 i:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA 2 s:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority---Server certificate-----BEGIN CERTIFICATE-----...-----END CERTIFICATE-----subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=*.googleapis.comissuer=/C=US/O=Google Inc/CN=Google Internet Authority G2---No client certificate CA names sent---SSL handshake has read 3820 bytes and written 431 bytes---New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256Server public key is 2048 bitSecure Renegotiation IS supportedCompression: NONEExpansion: NONESSL-Session: Protocol : TLSv1.2 Cipher : ECDHE-RSA-AES128-GCM-SHA256 Session-ID: ... Session-ID-ctx: Master-Key: ... Key-Arg : None PSK identity: None PSK identity hint: None SRP username: None TLS session ticket lifetime hint: 100800 (seconds) TLS session ticket: 0000 - ... .... Start Time: 1454060879 Timeout : 300 (sec) Verify return code: 0 (ok)---No idea if this is a valid approach, but when I tried:import requestsimport certifiAPI_KEY = "AIza..."url = ("https://maps.googleapis.com/maps/api/directions/json?" "origin=75+9th+Ave+New+York,+NY&" "destination=MetLife+Stadium+1+MetLife+Stadium+Dr+East+Rutherford,+NJ+07073&" "key=%s") % (API_KEY)r = requests.get(url, verify=certifi.where())The result was:Traceback (most recent call last): File "get_times.py", line 10, in <module> r = requests.get(url, verify=certifi.where()) File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 67, in get return request('get', url, params=params, **kwargs) File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 53, in request return session.request(method=method, url=url, **kwargs) File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 468, in request resp = self.send(prep, **send_kwargs) File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 576, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 447, in send raise SSLError(e, request=request)requests.exceptions.SSLError: bad handshake: Error([('SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed')],)I'm not running this on any server or hosting... I'm just trying to make it work as a simple CLI script on my PC... 解决方案 Thanks to Liam Horne for his answer here: https://stackoverflow.com/a/34665344/552621 I found a solution. There seems to be a major issue in the version of certifi that was running. I found this out from this (very long) GitHub issue: https://github.com/certifi/python-certifi/issues/26 TL;DR pip uninstall -y certifi && pip install certifi==2015.04.28 这篇关于如何使谷歌地图python库检测SSL证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-11 13:08