2017-02-24 8 views
0

ジオコーダーからgeocodersを実行しようとしているときにサービスエラーが発生しました.popthonで座標を取得するためにジオコーダーから位置座標を取得しようとしています。 なぜこのエラーが発生するのかわかりません。私がこれに対して行った検索から、これはプロキシの問題かもしれないが、私はすでにそれを設定しているようだ。 ここで何が問題になりますか?ジオコーダPythonでサービスエラーが発生しました

これは私のコードです:

from geopy import geocoders 

proxies={'http': 'http://location:port', 'https': 'http://localhost:port'} 
api_key = '.......' 

g = geocoders.GoogleV3(api_key=api_key,proxies=proxies, timeout=10) 

location = 'Mountain View, CA' 
try: 
    place, (lat, lng) = g.geocode(location) 
except ValueError as error_message: 
    print("Error: geocode failed on input %s with message %s" % (location, error_message)) 

これは私のエラー出力です:

Traceback (most recent call last): 
    File "/Users/aqm1152/anaconda/lib/python3.5/urllib/request.py", line 1254, in do_open 
    h.request(req.get_method(), req.selector, req.data, headers) 
    File "/Users/aqm1152/anaconda/lib/python3.5/http/client.py", line 1106, in request 
    self._send_request(method, url, body, headers) 
    File "/Users/aqm1152/anaconda/lib/python3.5/http/client.py", line 1151, in _send_request 
    self.endheaders(body) 
    File "/Users/aqm1152/anaconda/lib/python3.5/http/client.py", line 1102, in endheaders 
    self._send_output(message_body) 
    File "/Users/aqm1152/anaconda/lib/python3.5/http/client.py", line 934, in _send_output 
    self.send(msg) 
    File "/Users/aqm1152/anaconda/lib/python3.5/http/client.py", line 877, in send 
    self.connect() 
    File "/Users/aqm1152/anaconda/lib/python3.5/http/client.py", line 1260, in connect 
    server_hostname=server_hostname) 
    File "/Users/aqm1152/anaconda/lib/python3.5/ssl.py", line 377, in wrap_socket 
    _context=self) 
    File "/Users/aqm1152/anaconda/lib/python3.5/ssl.py", line 752, in __init__ 
    self.do_handshake() 
    File "/Users/aqm1152/anaconda/lib/python3.5/ssl.py", line 988, in do_handshake 
    self._sslobj.do_handshake() 
    File "/Users/aqm1152/anaconda/lib/python3.5/ssl.py", line 633, in do_handshake 
    self._sslobj.do_handshake() 
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:645) 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "/Users/aqm1152/anaconda/lib/python3.5/site-packages/geopy/geocoders/base.py", line 143, in _call_geocoder 
    page = requester(req, timeout=(timeout or self.timeout), **kwargs) 
    File "/Users/aqm1152/anaconda/lib/python3.5/urllib/request.py", line 163, in urlopen 
    return opener.open(url, data, timeout) 
    File "/Users/aqm1152/anaconda/lib/python3.5/urllib/request.py", line 466, in open 
    response = self._open(req, data) 
    File "/Users/aqm1152/anaconda/lib/python3.5/urllib/request.py", line 484, in _open 
    '_open', req) 
    File "/Users/aqm1152/anaconda/lib/python3.5/urllib/request.py", line 444, in _call_chain 
    result = func(*args) 
    File "/Users/aqm1152/anaconda/lib/python3.5/urllib/request.py", line 1297, in https_open 
    context=self._context, check_hostname=self._check_hostname) 
    File "/Users/aqm1152/anaconda/lib/python3.5/urllib/request.py", line 1256, in do_open 
    raise URLError(err) 
urllib.error.URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:645)> 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "/Users/aqm1152/Documents/TestingCode/ACERT/test_1.py", line 12, in <module> 
    place, (lat, lng) = g.geocode(location) 
    File "/Users/aqm1152/anaconda/lib/python3.5/site-packages/geopy/geocoders/googlev3.py", line 217, in geocode 
    self._call_geocoder(url, timeout=timeout), exactly_one 
    File "/Users/aqm1152/anaconda/lib/python3.5/site-packages/geopy/geocoders/base.py", line 171, in _call_geocoder 
    raise GeocoderServiceError(message) 
geopy.exc.GeocoderServiceError: EOF occurred in violation of protocol (_ssl.c:645) 

答えて

0

私はプロキシを使用し、APIを適用し、それはありませんように私には、以下のようにコードを修正私のマシンで動作します。

from geopy import geocoders 

#proxies={'http': 'http://location:port', 'https': 'http://localhost:port'} 
#api_key = '.......' 

g = geocoders.GoogleV3() 

location = 'Mountain View, CA' 
try: 
    place, (lat, lng) = g.geocode(location) 
except ValueError as error_message: 
    print("Error: geocode failed on input %s with message %s" % (location, error_message)) 

print (place, lat, lng) 

結果は次のとおりです。

Mountain View, CA, USA 37.3860517 -122.0838511 

トラックバックから、すべてのエラーがSSLに関連しているように見えます。代わりにSSL証明書の確認を無効にするには、最初に以下のコードを追加してみてください。

import ssl 

# Disable SSL certificate verification 
try: 
    _create_unverified_https_context = ssl._create_unverified_context 
except AttributeError: 
    # Legacy Python that doesn't verify HTTPS certificates by default 
    pass 
else: 
    # Handle target environment that doesn't support HTTPS verification 
    ssl._create_default_https_context = _create_unverified_https_context 

私は、Python 3.6を実行しているrootenvにはPython 2.7を実行しているアナコンダで同様の問題に遭遇しました。 Python 2.7を別のマシンで実行しているrootenvのAnacondaで問題は発生しませんでした。

this SO postgeopyを使用してプロキシサーバーを設定すると、osモジュールが参考になる場合があります。

このヘルプが必要です。

関連する問題