pip install fails when installing mlflow - pip

I'm working on a Window 10 machine and trying to pip install mlflow but I'm getting the following error message.
Traceback (most recent call last):
File "C:\Users\username\AppData\Local\Continuum\anaconda3\lib\site-packages\pip\_vendor\urllib3\response.py", line 360, in _error_catcher
yield
File "C:\Users\username\AppData\Local\Continuum\anaconda3\lib\site-packages\pip\_vendor\urllib3\response.py", line 442, in read
data = self._fp.read(amt)
File "C:\Users\username\AppData\Local\Continuum\anaconda3\lib\http\client.py", line 447, in read
n = self.readinto(b)
File "C:\Users\username\AppData\Local\Continuum\anaconda3\lib\http\client.py", line 491, in readinto
n = self.fp.readinto(b)
File "C:\Users\username\AppData\Local\Continuum\anaconda3\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "C:\Users\username\AppData\Local\Continuum\anaconda3\lib\ssl.py", line 1052, in recv_into
return self.read(nbytes, buffer)
File "C:\Users\username\AppData\Local\Continuum\anaconda3\lib\ssl.py", line 911, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
....
During handling of the above exception, another exception occurred:
What's this issue?

This seems due to some bad network setup issues - as you can observe from the fact that you have a socket timeout on what appears to be a pip install.

Related

pip error while installing django, kivy and other modules

I installed python 3.10 then tried to install django but it just starts downloading by after it reaches a certain point it crashes and shows this error Exception:
Traceback (most recent call last):
File
"c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_vendor\urllib3\response.py",
line 302, in _error_catcher
yield File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_vendor\urllib3\response.py",
line 384, in read
data = self._fp.read(amt) File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_vendor\cachecontrol\filewrapper.py",
line 60, in read
data = self.__fp.read(amt) File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\http\client.py",
line 447, in read
n = self.readinto(b) File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\http\client.py",
line 491, in readinto
n = self.fp.readinto(b) File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\socket.py",
line 589, in readinto
return self._sock.recv_into(b) File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\ssl.py",
line 1049, in recv_into
return self.read(nbytes, buffer) File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\ssl.py",
line 908, in read
return self._sslobj.read(len, buffer) socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File
"c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_internal\basecommand.py",
line 228, in main
status = self.run(options, args) File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_internal\commands\install.py",
line 291, in run
resolver.resolve(requirement_set) File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_internal\resolve.py",
line 103, in resolve
self._resolve_one(requirement_set, req) File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_internal\resolve.py",
line 257, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install) File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_internal\resolve.py",
line 210, in _get_abstract_dist_for
self.require_hashes File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_internal\operations\prepare.py",
line 310, in prepare_linked_requirement
progress_bar=self.progress_bar File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_internal\download.py",
line 837, in unpack_url
progress_bar=progress_bar File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_internal\download.py",
line 674, in unpack_http_url
progress_bar) File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_internal\download.py",
line 898, in _download_http_url
_download_url(resp, link, content_file, hashes, progress_bar) File
"c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_internal\download.py",
line 618, in _download_url
hashes.check_against_chunks(downloaded_chunks) File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_internal\utils\hashes.py",
line 48, in check_against_chunks
for chunk in chunks: File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_internal\download.py",
line 586, in written_chunks
for chunk in chunks: File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_internal\utils\ui.py",
line 159, in iter
for x in it: File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_internal\download.py",
line 575, in resp_read
decode_content=False): File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_vendor\urllib3\response.py",
line 436, in stream
data = self.read(amt=amt, decode_content=decode_content) File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_vendor\urllib3\response.py",
line 401, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining) File
"c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\contextlib.py",
line 130, in exit
self.gen.throw(type, value, traceback) File "c:\users\gabraham.aecigroup\appdata\local\programs\python\python37\lib\site-packages\pip_vendor\urllib3\response.py",
line 307, in _error_catcher
raise ReadTimeoutError(self._pool, None, 'Read timed out.') pip._vendor.urllib3.exceptions.ReadTimeoutError:
HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read
timed out.
So I tried to replace python 3.10 with version 3.7.0 but I am still getting the same error. How do I avoid this error?
check here, probably you have bad connection to internet or the download takes too long...

Timeout when trying to install Qiskit on macOS

I am trying to install Qiskit 0.20.0 on my machine running macOS and seeing the below error
pip install qiskit
Collecting qiskit
Using cached qiskit-0.20.0.tar.gz (4.0 kB)
Collecting qiskit-terra==0.15.1
Downloading qiskit_terra-0.15.1-cp38-cp38-macosx_10_9_x86_64.whl (7.6 MB)
|██▏ | 522 kB 7.7 kB/s eta 0:15:22ERROR: Exception:
Traceback (most recent call last):
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 437, in _error_catcher
yield
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 519, in read
data = self._fp.read(amt) if not fp_closed else b""
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_vendor/cachecontrol/filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/http/client.py", line 458, in read
n = self.readinto(b)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/http/client.py", line 502, in readinto
n = self.fp.readinto(b)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 216, in _main
status = self.run(options, args)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 182, in wrapper
return func(self, options, args)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 324, in run
requirement_set = resolver.resolve(
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/resolution/legacy/resolver.py", line 183, in resolve
discovered_reqs.extend(self._resolve_one(requirement_set, req))
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/resolution/legacy/resolver.py", line 388, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/resolution/legacy/resolver.py", line 340, in _get_abstract_dist_for
abstract_dist = self.preparer.prepare_linked_requirement(req)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 467, in prepare_linked_requirement
local_file = unpack_url(
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 255, in unpack_url
file = get_http_url(
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 129, in get_http_url
from_path, content_type = _download_http_url(
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 282, in _download_http_url
for chunk in download.chunks:
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/cli/progress_bars.py", line 168, in iter
for x in it:
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/network/utils.py", line 64, in response_chunks
for chunk in response.raw.stream(
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 576, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 541, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/contextlib.py", line 131, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 442, in _error_catcher
raise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
The anaconda version on my machine is 4.8.4 and Python version is 3.8.5.
I have followed the instructions mentioned here and created a virtual environment before running
pip install qiskit
This looks like it's just a network issue. The error is a timeout trying to read from files.pythonhosted.org when pip was downloading the qiskit-terra package from PyPI. There isn't really anything you can do except to try again in such cases. If you're on a slow and/or unreliable internet connection it might take several tries take a few tries for the download of all the qiskit packages (and their dependencies) to succeed.

bot.get_me() doesn't work and raises an error

I can manually interact with the bot through url. For example when I send a request to api.telegram.com/bot-token/getMe
the bot's basic info is returned I even get correct results using requests library in python shell but when I try bot.get_me() in the python shell it doesn't work and says this
Traceback (most recent call last):
File "C:\Users\YM\AppData\Local\Programs\Python\Python38-32\lib\site-packages\
telegram\vendor\ptb_urllib3\urllib3\connection.py", line 140, in _new_conn
conn = connection.create_connection(
File "C:\Users\YM\AppData\Local\Programs\Python\Python38-32\lib\site-packages\
telegram\vendor\ptb_urllib3\urllib3\util\connection.py", line 83, in create_conn
ection
raise err
File "C:\Users\YM\AppData\Local\Programs\Python\Python38-32\lib\site-packages\
telegram\vendor\ptb_urllib3\urllib3\util\connection.py", line 73, in create_conn
ection
sock.connect(sa)
socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\YM\AppData\Local\Programs\Python\Python38-32\lib\site-packages\
telegram\vendor\ptb_urllib3\urllib3\connectionpool.py", line 614, in urlopen
httplib_response = self._make_request(conn, method, url,
File "C:\Users\YM\AppData\Local\Programs\Python\Python38-32\lib\site-packages\
telegram\vendor\ptb_urllib3\urllib3\connectionpool.py", line 360, in _make_reque
st
self._validate_conn(conn)
File "C:\Users\YM\AppData\Local\Programs\Python\Python38-32\lib\site-packages\
telegram\vendor\ptb_urllib3\urllib3\connectionpool.py", line 857, in _validate_c
onn
super(HTTPSConnectionPool, self)._validate_conn(conn)
File "C:\Users\YM\AppData\Local\Programs\Python\Python38-32\lib\site-packages\
telegram\vendor\ptb_urllib3\urllib3\connectionpool.py", line 289, in _validate_c
onn
conn.connect()
File "C:\Users\YM\AppData\Local\Programs\Python\Python38-32\lib\site-packages\
telegram\vendor\ptb_urllib3\urllib3\connection.py", line 284, in connect
conn = self._new_conn()
File "C:\Users\YM\AppData\Local\Programs\Python\Python38-32\lib\site-packages\
telegram\vendor\ptb_urllib3\urllib3\connection.py", line 144, in _new_conn
raise ConnectTimeoutError(
telegram.vendor.ptb_urllib3.urllib3.exceptions.ConnectTimeoutError: (<telegram.v
endor.ptb_urllib3.urllib3.connection.VerifiedHTTPSConnection object at 0x024257F
0>, 'Connection to api.telegram.org timed out. (connect timeout=5.0)')
Looks like you're having problems with your internet connection, i.e. the request could not be finished within the timeout of 5 seconds. Keep in mind that a lot of problems can happen unexpectedly in networking. In fact python-telegram-bot has a wiki page dedicated to that topic. Ofc you could first try to simply increase the timeout, e.g. by passing timeout=<some_value_>5> to get_me.

How to set socks5 proxy in tweepy?

To ssh login my vps,the codes can run successfully.
import tweepy
consumer_key="xxx"
consumer_secret="xxx"
access_token="xxx"
access_token_secret="xxx"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
tweets = api.user_timeline(screen_name="realDonaldTrump",weet_mode="extended",count=200)
for info in tweets:
print(info.text)
Set all software related with proxy, and test socks proxy.
url="https://www.youtube.com/watch?v=l9AC98amjSA"
youtube-dl --proxy socks5://127.0.0.1:1080 $url -o /tmp/downName
It is verified that the video on youtube can be downloaded with socks5 proxy.
All software related with proxy are in good status.
Now i want to set socks5 proxy in my local pc,only one line was changed based on the above codes.
api = tweepy.API(auth,proxy="127.0.0.1:1080")
The error info is as following.
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 588, in urlopen
self._prepare_proxy(conn)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 803, in _prepare_proxy
conn.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 291, in connect
self._tunnel()
File "/usr/lib/python3.5/http/client.py", line 827, in _tunnel
(version, code, message) = response._read_status()
File "/usr/lib/python3.5/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.5/socket.py", line 576, in readinto
return self._sock.recv_into(b)
socket.timeout: timed out
It is no use also to add socks proxy statement as following.
import urllib.request
proxy_support = urllib.request.ProxyHandler({'sock5': 'localhost:1080'})
opener = urllib.request.build_opener(proxy_support)
urllib.request.install_opener(opener)
import tweepy
consumer_key="xxx"
consumer_secret="xxx"
access_token="xxx"
access_token_secret="xxx"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth) # or api = tweepy.API(auth,proxy="127.0.0.1:1080")
tweets = api.user_timeline(screen_name="realDonaldTrump",weet_mode="extended",count=200)
for info in tweets:
print(info.text)
How to set socks5 proxy in tweepy?
According to Tarun Lalwani,package installed and codes changed ,still don't work.
sudo pip3 install -U requests[socks]
Set all related proxy software.
sudo netstat -anlp |grep 1080
tcp 0 0 127.0.0.1:1080 0.0.0.0:* LISTEN 1465/python3
udp 0 0 127.0.0.1:1080 0.0.0.0:* 1465/python3
Then enter into python3 console.
import tweepy
consumer_key="xxx"
consumer_secret="xxx"
access_token="xxx"
access_token_secret="xxx"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth,proxy="socks5://127.0.0.1:1080")
tweets = api.user_timeline(screen_name="realDonaldTrump",weet_mode="extended",count=200)
An other error info occur.
tweets = api.user_timeline(screen_name="realDonaldTrump",weet_mode="extended",count=200)
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/urllib3/contrib/pyopenssl.py", line 441, in wrap_socket
cnx.do_handshake()
File "/usr/local/lib/python3.5/dist-packages/OpenSSL/SSL.py", line 1716, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "/usr/local/lib/python3.5/dist-packages/OpenSSL/SSL.py", line 1431, in _raise_ssl_error
raise WantReadError()
OpenSSL.SSL.WantReadError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 346, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 850, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.5/dist-packages/urllib3/connection.py", line 326, in connect
ssl_context=context)
File "/usr/local/lib/python3.5/dist-packages/urllib3/util/ssl_.py", line 329, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/local/lib/python3.5/dist-packages/urllib3/contrib/pyopenssl.py", line 445, in wrap_socket
raise timeout('select timed out')
socket.timeout: select timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/local/lib/python3.5/dist-packages/urllib3/util/retry.py", line 357, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/local/lib/python3.5/dist-packages/urllib3/packages/six.py", line 686, in reraise
raise value
File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 349, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 309, in _raise_timeout
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
urllib3.exceptions.ReadTimeoutError: SOCKSHTTPSConnectionPool(host='api.twitter.com', port=443): Read timed out. (read timeout=60)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tweepy/binder.py", line 187, in execute
proxies=self.api.proxy)
File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 521, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: SOCKSHTTPSConnectionPool(host='api.twitter.com', port=443): Read timed out. (read timeout=60)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/tweepy/binder.py", line 245, in _call
return method.execute()
File "/usr/local/lib/python3.5/dist-packages/tweepy/binder.py", line 189, in execute
raise TweepError('Failed to send request: %s' % e)
tweepy.error.TweepError: Failed to send request: SOCKSHTTPSConnectionPool(host='api.twitter.com', port=443): Read timed out. (read timeout=60)
Two things. One you need the requests[socks] package
pip install requests[socks]
Next you need to use the proxy in socks format
api = tweepy.API(auth,proxy="socks5://127.0.0.1:1080")

geocoder Service error in python

I am having a service error as I am trying to run geocoders from geopy to get a location coordinates in python.I have set my proxy config, given it an api_key.
Im not sure why I am getting this error. From the search that I have done on this, it seems that this might be a proxy issue but I have that set up already.
What could be the problem here?
This is my code :
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))
this is my error output:
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)
I modified your code as below, as I don't use proxy and apply an API, and it works in my machine.
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)
Here is the result.
Mountain View, CA, USA 37.3860517 -122.0838511
From the trackback, it looks all the errors are related to SSL. You may try to add below code at the beginning to disable SSL Certification verification as an alternative.
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
I have encountered similar problem in Anaconda running Python 2.7 in a env with the root running Python 3.6. The problem wasn't encountered in Anaconda with both root and env running Python 2.7 in another machine.
In addition, this SO post about proxy server set up for geopy using os module may be good reference.
Hope this help.

Resources