ssl.SSLError: tlsv1 alert protocol version - python
I'm using the REST API for a Cisco CMX device, and trying to write Python code which makes a GET request to the API for information. The code is as follows and is the same as that in the file except with the necessary information changed.
from http.client import HTTPSConnection
from base64 import b64encode
# Create HTTPS connection
c = HTTPSConnection("0.0.0.0")
# encode as Base64
# decode to ascii (python3 stores as byte string, need to pass as ascii
value for auth)
username_password = b64encode(b"admin:password").decode("ascii")
headers = {'Authorization': 'Basic {0}'.format(username_password)}
# connect and ask for resource
c.request('GET', '/api/config/v1/aaa/users', headers=headers)
# response
res = c.getresponse()
data = res.read()
However, I am continuously getting the following error:
Traceback (most recent call last):
File "/Users/finaris/PycharmProjects/test/test/test.py", line 14, in <module>
c.request('GET', '/api/config/v1/aaa/users', headers=headers)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1106, in request
self._send_request(method, url, body, headers)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1151, in _send_request
self.endheaders(body)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1102, in endheaders
self._send_output(message_body)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 934, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 877, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1260, in connect
server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 377, in wrap_socket
_context=self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 752, in __init__
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 988, in do_handshake
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 633, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:645)
I also tried updating OpenSSL but that had no effect.
I had the same error and google brought me to this question, so here is what I did, hoping that it helps others in a similar situation.
This is applicable for OS X.
Check in the Terminal which version of OpenSSL I had:
$ python3 -c "import ssl; print(ssl.OPENSSL_VERSION)"
>> OpenSSL 0.9.8zh 14 Jan 2016
As my version of OpenSSL was too old, the accepted answer did not work.
So I had to update OpenSSL. To do this, I updated Python to the latest version (from version 3.5 to version 3.6) with Homebrew, following some of the steps suggested here:
$ brew update
$ brew install openssl
$ brew install python3
Then I was having problems with the PATH and the version of python being used, so I just created a new virtualenv making sure that the newest version of python was taken:
$ virtualenv webapp --python=python3.6
Issue solved.
The only thing you have to do is to install requests[security] in your virtualenv. You should not have to use Python 3 (it should work in Python 2.7). Moreover, if you are using a recent version of macOS, you don't have to use homebrew to separately install OpenSSL either.
$ virtualenv --python=/usr/bin/python tempenv # uses system python
$ . tempenv/bin/activate
$ pip install requests
$ python
>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 0.9.8zh 14 Jan 2016' # this is the built-in openssl
>>> import requests
>>> requests.get('https://api.github.com/users/octocat/orgs')
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: /users/octocat/orgs (Caused by SSLError(SSLError(1, u'[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590)'),))
$ pip install 'requests[security]'
$ python # install requests[security] and try again
>>> import requests
>>> requests.get('https://api.github.com/users/octocat/orgs')
<Response [200]>
requests[security] allows requests to use the latest version of TLS when negotiating the connection. The built-in openssl on macOS supports TLS v1.2.
Before you install your own version of OpenSSL, ask this question: how is Google Chrome loading https://github.com?
I believe TLSV1_ALERT_PROTOCOL_VERSION is alerting you that the server doesn't want to talk TLS v1.0 to you. Try to specify TLS v1.2 only by sticking in these lines:
import ssl
from http.client import HTTPSConnection
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
# Create HTTPS connection
c = HTTPSConnection("0.0.0.0", context=context)
Note, you may need sufficiently new versions of Python (2.7.9+ perhaps?) and possibly OpenSSL (I have "OpenSSL 1.0.2k 26 Jan 2017" and the above seems to work, YMMV)
None of the accepted answers pointed me in the right direction, and this is still the question that comes up when searching the topic, so here's my (partially) successful saga.
Background: I run a Python script on a Beaglebone Black that polls the cryptocurrency exchange Poloniex using the python-poloniex library. It suddenly stopped working with the TLSV1_ALERT_PROTOCOL_VERSION error.
Turns out that OpenSSL was fine, and trying to force a v1.2 connection was a huge wild goose chase - the library will use the latest version as necessary. The weak link in the chain was actually Python, which only defined ssl.PROTOCOL_TLSv1_2, and therefore started supporting TLS v1.2, since version 3.4.
Meanwhile, the version of Debian on the Beaglebone considers Python 3.3 the latest. The workaround I used was to install Python 3.5 from source (3.4 might have eventually worked too, but after hours of trial and error I'm done):
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
wget https://www.python.org/ftp/python/3.5.4/Python-3.5.4.tgz
sudo tar xzf Python-3.5.4.tgz
cd Python-3.5.4
./configure
sudo make altinstall
Maybe not all those packages are strictly necessary, but installing them all at once saves a bunch of retries. The altinstall prevents the install from clobbering existing python binaries, installing as python3.5 instead, though that does mean you have to re-install additional libraries. The ./configure took a good five or ten minutes. The make took a couple of hours.
Now this still didn't work until I finally ran
sudo -H pip3.5 install requests[security]
Which also installs pyOpenSSL, cryptography and idna. I suspect pyOpenSSL was the key, so maybe pip3.5 install -U pyopenssl would have been sufficient but I've spent far too long on this already to make sure.
So in summary, if you get TLSV1_ALERT_PROTOCOL_VERSION error in Python, it's probably because you can't support TLS v1.2. To add support, you need at least the following:
OpenSSL 1.0.1
Python 3.4
requests[security]
This has got me past TLSV1_ALERT_PROTOCOL_VERSION, and now I get to battle with SSL23_GET_SERVER_HELLO instead.
Turns out this is back to the original issue of Python selecting the wrong SSL version. This can be confirmed by using this trick to mount a requests session with ssl_version=ssl.PROTOCOL_TLSv1_2. Without it, SSLv23 is used and the SSL23_GET_SERVER_HELLO error appears. With it, the request succeeds.
The final battle was to force TLSv1_2 to be picked when the request is made deep within a third party library. Both this method and this method ought to have done the trick, but neither made any difference. My final solution is horrible, but effective. I edited /usr/local/lib/python3.5/site-packages/urllib3/util/ssl_.py and changed
def resolve_ssl_version(candidate):
"""
like resolve_cert_reqs
"""
if candidate is None:
return PROTOCOL_SSLv23
if isinstance(candidate, str):
res = getattr(ssl, candidate, None)
if res is None:
res = getattr(ssl, 'PROTOCOL_' + candidate)
return res
return candidate
to
def resolve_ssl_version(candidate):
"""
like resolve_cert_reqs
"""
if candidate is None:
return ssl.PROTOCOL_TLSv1_2
if isinstance(candidate, str):
res = getattr(ssl, candidate, None)
if res is None:
res = getattr(ssl, 'PROTOCOL_' + candidate)
return res
return candidate
and voila, my script can finally contact the server again.
As of July 2018, Pypi now requires that clients connecting to it use TLS 1.2. This is an issue if you're using the version of python shipped with MacOS (2.7.10) because it only supports TLS 1.0. You can change the version of ssl that python is using to fix the problem or upgrade to a newer version of python. Use homebrew to install the new version of python outside of the default library location.
brew install python#2
For Mac OS X
1) Update to Python 3.6.5 using the native app installer downloaded from the official Python language website https://www.python.org/downloads/
I've found that the installer is taking care of updating the links and symlinks for the new Python a lot better than homebrew.
2) Install a new certificate using "./Install Certificates.command" which is in the refreshed Python 3.6 directory
> cd "/Applications/Python 3.6/"
> sudo "./Install Certificates.command"
Another source of this problem: I found that in Debian 9, the Python httplib2 is hardcoded to insist on TLS v1.0. So any application that uses httplib2 to connect to a server that insists on better security fails with TLSV1_ALERT_PROTOCOL_VERSION.
I fixed it by changing
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
to
context = ssl.SSLContext()
in /usr/lib/python3/dist-packages/httplib2/__init__.py .
Debian 10 doesn't have this problem.
I got this problem too.
In macos, here is the solution:
Step 1: brew restall python. now you got python3.7 instead of the old python
Step 2: build the new env base on python3.7. my path is /usr/local/Cellar/python/3.7.2/bin/python3.7
now, you'll not being disturbed by this problem.
I encountered this exact issue when I attempted gem install bundler, and I was confused by all the Python responses (since I was using Ruby). Here was my exact error:
ERROR: Could not find a valid gem 'bundler' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: tlsv1 alert protocol version (https://rubygems.org/latest_specs.4.8.gz)
My solution: I updated Ruby to the most recent version (2.6.5). Problem solved.
I ran into this issue using Flask with the flask_mqtt extension. The solution was to add this to the Python file:
app.config['MQTT_TLS_VERSION'] = ssl.PROTOCOL_TLSv1_2
Related
How do i solve ssl error when using pip install [duplicate]
I would retrieve some information from an ABB G13 gateway that offer a RESTful JSON API. API is hosted by the gateway via https endpoint. Basic authentication mechanism is used for authentication. However all traffic goes through SSL layers. On linux with command: curl -s -k -X GET -u user:password https://host/meters/a_serial/power All goes well! I'm trying to write a script for windows in Python 2.7.10 with Requests 2.8.1 and with this code: import requests requests.get('https://host/meters/a_serial/power', auth=('user', 'password')) I have this error: Traceback (most recent call last): File "C:/Users/mzilio/PycharmProjects/pwrgtw/test.py", line 20, in <module> requests.get('https://host/meters/a_serial/power', auth=('user', 'password')) File "C:\Python27\lib\site-packages\requests\api.py", line 69, in get return request('get', url, params=params, **kwargs) File "C:\Python27\lib\site-packages\requests\api.py", line 50, in request response = session.request(method=method, url=url, **kwargs) File "C:\Python27\lib\site-packages\requests\sessions.py", line 468, in request resp = self.send(prep, **send_kwargs) File "C:\Python27\lib\site-packages\requests\sessions.py", line 576, in send r = adapter.send(request, **kwargs) File "C:\Python27\lib\site-packages\requests\adapters.py", line 433, in send raise SSLError(e, request=request) requests.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:590) I've searched for a solution and I've tried to fix with this code: import requests from requests.adapters import HTTPAdapter from requests.packages.urllib3.poolmanager import PoolManager import ssl class MyAdapter(HTTPAdapter): def init_poolmanager(self, connections, maxsize, block=False): self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize, block=block, ssl_version=ssl.PROTOCOL_TLSv1) s = requests.Session() s.mount('https://', MyAdapter()) s.get('https://host/meters/a_serial/power') But it doesn't work for me cause I get this error: Traceback (most recent call last): File "C:/Users/mzilio/PycharmProjects/pwrgtw/test.py", line 16, in <module> s.get('https://host/meters/a_serial/power') File "C:\Python27\lib\site-packages\requests\sessions.py", line 480, in get return self.request('GET', url, **kwargs) File "C:\Python27\lib\site-packages\requests\sessions.py", line 468, in request resp = self.send(prep, **send_kwargs) File "C:\Python27\lib\site-packages\requests\sessions.py", line 576, in send r = adapter.send(request, **kwargs) File "C:\Python27\lib\site-packages\requests\adapters.py", line 433, in send raise SSLError(e, request=request) requests.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:590) I'm stuck on this problem. Could someone help me? Thanks!
This thing worked for me, just make sure whether these modules are installed or not, if not then install them, following are: pip install ndg-httpsclient pip install pyopenssl pip install pyasn1 It removed my SSLError: EOF occurred in violation of protocol (_ssl.c:590) error. Hope it helps.
Step 1: Check that Python supports TLS 1.1 You may have a Python setup that only supports TLS 1.0 – not TLS 1.1 or above. You can check it like this: Python 3 from urllib.request import urlopen urlopen('https://www.howsmyssl.com/a/check').read() Python 2 from urllib2 import urlopen urlopen('https://www.howsmyssl.com/a/check').read() (If you get urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)> you may have to disable certificate verification. NOTE: doing this will disable SSL protections against evildoers who would impersonate or intercept traffic to that website - see https://en.wikipedia.org/wiki/Man-in-the-middle_attack ) import ssl urlopen('https://www.howsmyssl.com/a/check', context=ssl._create_unverified_context()).read() Check the output for the key tls_version. If it says TLS 1.0 and not TLS 1.1 or TLS 1.2 that could be the problem. If you're using a virtualenv, be sure to run the command inside. Step 2: Install Python with a newer version of OpenSSL In order support TLS 1.1 or above, you may need to install a newer version of OpenSSL, and the install Python again afterwards. This should give you a Python that supports TLS 1.1. The process depends on your operating system – here's a guide for OS X. virtualenv users For me, the Python outside of my virtualenv had TLS 1.2 support, so just I removed my old virtualenv, and created a new one with the same packages and then it worked. Easy peasy!
I found it was going through a proxy when it should have connected to the server directly. I fixed this by doing unset https_proxy
I had exactly the same error, turns out that I didn't have ndg-httpsclient installed, see my original issue raised in github.
If you are getting this error for intermediate requests, you can refer to the solution mentioned in https://github.com/requests/requests/issues/3391. Basically, if you are making a lot of requests to a server and facing this issue with some of those requests you can use Session to just retry the requests. Let me know if this works.
Close you proxy and try it again.
The only time I have seen errors of this nature have been times that I was using requests to screen scrape data and I was using a multiprocessing library. I would either try your code without the pool manager or split your app into two apps, one that doles out urls and another that consumes them. The client-server pair here should give you some ideas. I was able to scale my client out horizontally when I used the hacky server code to load all urls into a Queue in memory just before app.run. Hope that helps.
ENV: Python 3.10, www.howsmyssl.com returns tls_version: TLS 1.3: For poor guys like me who MUST make query thorough proxy, this cloud be blame on your incorrect HTTPS proxy setting (perhaps you aren't set it, but python somehow believes you've set it, don't know why exactly, maybe because you've set the http proxy), you need to set it "properly". I'm using windows10, haven't set it before, after set it, python works normally, give it a try.
try to run: pip install urllib3==1.25.11 It works for me anyway.
OpenSSL: error:1409442E:SSL routines:ssl3_read_bytes:tlsv1 alert protocol version
wget -O /Users/itaybd/Finzor_2_26/dev_code/Engine/DATA/EOD/S_temp.zip https://www.quandl.com/api/v3/datatables/SHARADAR/SEP?qopts.export=true&api_key=MYKEY yield OpenSSL: error:1409442E Where import requests url = 'https://www.howsmyssl.com/a/check' r = requests.get(url) print(r.json()['tls_version']) Yields: TLS 1.2 How to fix this ????
If your server doesn't support TLS 1.0 you can try running wget with the option --secure-protocol=TLSv1_2 If your version of wget is older than 1.14 and your server uses SNI, upgrade wget to at least 1.14. Please let us know which of these fixes it, and if neither fixes it then let us know more information about the problem (such as the versions of the software you are using including wget and openssl, and the full error from wget).
python socket protocol not support
I useed python-can-isotp on RaspberryPi3, and test it with example code, but I got an error. My simple code: import isotp s = isotp.socket() s2 = isotp.socket() # Configuring the sockets. s.set_fc_opts(stmin=5, bs=10) #s.set_general_opts(...) #s.set_ll_opts(...) s.bind("vcan0" rxid=0x123 txid=0x456) # We love named parameters! s2.bind("vcan0", rxid=0x456, txid=0x123) s2.send(b"Hello, this is a long payload sent in small chunks of 8 bytes.") print(s.recv()) ERROR: File "/usr/local/opt/python-3.7.0/lib/python3.7/socket.py", line 151, in __init__ _socket.socket.__init__(self, family, type, proto, fileno) OSError: [Errno 93] Protocol not supported Can someone please help me find the solution to the problem?
I followed these instructions (with slight modifications) to make isotp work on a Raspberry Pi 3B+ with the latest Raspbian Stretch. Here is the exact sequence of commands I carried out: sudo apt update sudo apt upgrade git clone https://github.com/hartkopp/can-isotp.git cd can-isotp sudo apt install build-essential raspberrypi-kernel-headers make install sudo make modules_install modprobe can sudo insmod ./net/can/can-isotp.ko However, I don't use it in Python. I simply tested the tools provided for use with isotp, such as e.g. isotpsend and isotprecv.
Python PIP Install throws TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
Using pip install for any module apparently on my Ubuntu 16.04 system with python 2.7.11+ throws this error: TypeError: unsupported operand type(s) for -=: 'Retry' and 'int' What is wrong with pip? How could I reinstall it, if necessary? Update: Full traceback is below sunny#sunny:~$ pip install requests Collecting requests Exception: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main status = self.run(options, args) File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 328, in run wb.build(autobuilding=True) File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 748, in build self.requirement_set.prepare_files(self.finder) File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 360, in prepare_files ignore_dependencies=self.ignore_dependencies)) File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 512, in _prepare_file finder, self.upgrade, require_hashes) File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 273, in populate_link self.link = finder.find_requirement(self, upgrade) File "/usr/lib/python2.7/dist-packages/pip/index.py", line 442, in find_requirement all_candidates = self.find_all_candidates(req.name) File "/usr/lib/python2.7/dist-packages/pip/index.py", line 400, in find_all_candidates for page in self._get_pages(url_locations, project_name): File "/usr/lib/python2.7/dist-packages/pip/index.py", line 545, in _get_pages page = self._get_page(location) File "/usr/lib/python2.7/dist-packages/pip/index.py", line 648, in _get_page return HTMLPage.get_page(link, session=self.session) File "/usr/lib/python2.7/dist-packages/pip/index.py", line 757, in get_page "Cache-Control": "max-age=600", File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 480, in get return self.request('GET', url, **kwargs) File "/usr/lib/python2.7/dist-packages/pip/download.py", line 378, in request return super(PipSession, self).request(method, url, *args, **kwargs) File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 468, in request resp = self.send(prep, **send_kwargs) File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 576, in send r = adapter.send(request, **kwargs) File "/usr/share/python-wheels/CacheControl-0.11.5-py2.py3-none-any.whl/cachecontrol/adapter.py", line 46, in send resp = super(CacheControlAdapter, self).send(request, **kw) File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/adapters.py", line 376, in send timeout=timeout File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 610, in urlopen _stacktrace=sys.exc_info()[2]) File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 228, in increment total -= 1 TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
Ubuntu comes with a version of PIP from precambrian and that's how you have to upgrade it if you do not want to spend hours and hours debugging pip related issues. apt-get remove python-pip python3-pip wget https://bootstrap.pypa.io/get-pip.py python get-pip.py python3 get-pip.py As you observed I included information for both Python 2.x and 3.x
If you are behind a proxy, you must do some extra configuration steps before starting the installation. You must set the environment variable http_proxy to the proxy address. Using bash this is accomplished with the command export http_proxy="http://user:pass#my.site:port/" You can also provide the --proxy=[user:pass#]url:port parameter to pip. The [user:pass#] portion is optional.
Updating setuptools has worked out fine for me. sudo pip install --upgrade setuptools
First of all, this problem exists because of network issues, and uninstalling and re-installing everything won't be of much help. Probably you are behind proxy, and in that case you need to set proxy. But in my case, I was facing the problem because I wasn't behind proxy. Generally, I work behind proxy, but when working from home, I set the proxy to None in Network settings. But I was still getting the same errors even after removing the proxy settings. So, when I did type env | grep proxy I found something like this : http_proxy=http://127.0.0.1:1234/ And this was the reason I was still getting the very same error, even when I thought I had removed the proxy settings. To unset this proxy, type unset http_proxy Follow the same approach for all the other entries, such as https_proxy.
What happens here is that the the vendored versions of request/urllib3 clash when imported in two different places (same code, but different names). If you then have a network error, it doesn't retry to get the wheel, but fails with the above error. See here for a deeper dive into this error. For the solution with system pip, see above. If you have this problem in a virtualenv built by python -m venv (which still copies the wheels from /usr/share/python-wheels, even if you have pip installed separately), the easiest way to "fix" it seems to be: create the virtualenv: /usr/bin/python3.6 -m venv ... install requests into the environment (this might raise the above error): <venv>/bin/pip install requests remove the copied versions of requests which would be used by pip: rm <venv>/share/python-wheels/{requests,chardet,urllib3}-*.whl Now a <venv>/bin/pip uses the installed version of requests which has urllib3 vendored.
port 443 is not open, just allow custom tcp port 443 if on AWS else open the port 443 for the outbound connections ...
Just upgrade pip worked for me: pip install --upgrade pip
I have the same problem when installing a RaspberryPI TFT from Adafruit with pitft.sh / adafruit-pitft.sh. I am not happy about coding-styles with errors from somewhere to be interpreted somehow - as could be seen by the previous answers. Remark: The type error exception of retry.py is obviously a bug, caused by an unappropriate assignement and calculation of an instance of the class Reply to an int with the default value of 10 - somewhere in the code... Should be fixed either by adding an inplace-operator, or fixing the erroneous assignment. So tried to analyse and patch the error itself first. The actual error in my case case is the same - retry.py called by pip. The installation script adafruit-pitft.sh / pitft.sh tries to apply urllib3 which itself tries to install nested dependencies by pip, so the same error. https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/master/adafruit-pitft.sh https://github.com/adafruit/Raspberry-Pi-Installer-Scripts adafruit-pitft.sh # or pitft.sh ... _stacktrace=sys.exc_info()[2]) File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3 none-any.whl/urllib3/util/retry.py", line 228, in increment total -= 1 TypeError: unsupported operand type(s) for -=: 'Retry' and 'int' For the current distribution(based on debian-9.6.0/stretch): File "/usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 315, in increment total -= 1 TypeError: unsupported operand type(s) for -=: 'Retry' and 'int' The following - dirty *:) - patch enables a sounding error trace: # File: retry.py - in *def increment(self, ..* about line 315 # original: total = self.total # patch: quick-and-dirty-fix # START: if isinstance(self.total, Retry): self.total = self.total.total if type(self.total) is not int: self.total = 2 # default is 10 # END: # continue with original: total = self.total if total is not None: total -= 1 connect = self.connect read = self.read redirect = self.redirect cause = 'unknown' status = None redirect_location = None if error and self._is_connection_error(error): # Connect retry? if connect is False: raise six.reraise(type(error), error, _stacktrace) elif connect is not None: connect -= 1 The sounding output with the temporary patch is(displayed twice...?): Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'ConnectTimeoutError(<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at/ Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'ConnectTimeoutError(<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at/ Could not find a version that satisfies the requirement evdev (from versions: ) No matching distribution found for evdev WARNING : Pip failed to install software! So in my case actually two things cause the error, this may vary in other environments: Missing evdev => try to install Failed to connect a repo/dist containing evdev in order to download. => finally give it up My installation environment is offline from an internal debian+raspbian mirror, thus do not want to set the proxy... So I proceeded by manual installation of the missing component evdev: download evdev from PyPI(or e.g. from github.com): https://pypi.org/project/evdev/ https://files.pythonhosted.org/packages/7e/53/374b82dd2ccec240b7388c65075391147524255466651a14340615aabb5f/evdev-1.1.2.tar.gz Unpack and install manually as root user - for all local accounts, so detected as installed: sudo su - tar xf evdev-1.1.2.tar.gz cd evdev-1.1.2 python setup.py install Call install script again: adafruit-pitft.sh # or pitft.sh ...Answer dialogues... ...that's it. If you proceed online by direct PyPI access: check your routing + firewall for access to pypi.org set a proxy if required (http_proxy/https_proxy) And it works.. Hope this helps in other cases too. Arno-Can Uestuensoez ---------------------------------------------- See also: issue - 35334: https://bugs.python.org/issue35334 ---------------------------------------------- See now also: issue - 1486: https://github.com/urllib3/urllib3/issues/1486 for file: https://github.com/urllib3/urllib3/blob/master/src/urllib3/util/retry.py
check for network issues, to bypass the exception case code In my case, I was using a custom index, that index had no route and such would trigger the exception case code. The exception case bug still exists and still masks the real issue, however I was able to work around this by testing the connectivity with other tools such as nc -vzw1 myindex.example.org 443 and retrying when the network was up.
I was facing similar issue while trying to install awscli tool on ec2 instance. I changed security group to allow port 443 inbound and outbound access and that solved the issue for me.
I got this error when I was trying to create a virtualenv with command virtualenv myVirtualEnv. I just added a sudo before the command; it solved everything.
Solution: 1. sudo apt remove python-pip 2. pip3 install pip (or install pip by get-pip.py) Why: This error occurred on pip 8.0.1 which installed by apt-get. And happened only when your network is unstable. If you have a pip installed with apt, it hides the pip you installed by other ways, so you should remove the apt one first. I disconnected the network and tested 8.0.1, 9.0.3, 10.x the 3 versions installed with pip3 or get-pip.py, no error occurred. So, I think only the apt version of pip 8.0.1 has that bug, the others is ok.
I tried the solution answered above: apt-get remove python-pip python3-pip wget https://bootstrap.pypa.io/get-pip.py python get-pip.py python3 get-pip.py When I tried python get-pip.py python3 get-pip.py I got this message Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: /usr/bin/pip3 Consider using the --user option or check the permissions. I did the following and it works python3 -m venv env source ./env/bin/activate Sudo apt-get update apt-get remove python-pip python3-pip wget https://bootstrap.pypa.io/get-pip.py python get-pip.py python3 get-pip.py pip3 install pip sudo easy_install pip pip install --upgrade pip
In my case, i had opened Pycharm in sudo mode, and was running pip install nltk in pycharm terminal which showed this error. running with sudo pip install solves the error.
I also had this issue. Initially, a proxy was set and work fine. Then I connected to a network where it doesn't go through a proxy. After unsetting proxy pip again get works. unset http_proxy; unset http_prox; unset HTTP_PROXY; unset HTTPS_PROXY
Bizarrely if I remove the proxy from the environment and add it to the command line it works for me. For example to upgrade pip itself: env http_proxy= https_proxy= pip install pip --upgrade --proxy 'http://proxy-url:80' My issue was having the proxy in the environment. It seems that pip only honors the one in argument.
This is the working solution to this problem I found. sudo apt-get clean cd /var/lib/apt sudo mv lists lists.old sudo mkdir -p lists/partial sudo apt-get clean sudo apt-get update
For myself, it turns out that wlan0 was down, which resulted in me being unable to connect out. So, ensuring that wlan0 was up, allowed pip / pip3 to work without issue.
fixed it temporary: pip install requests -i http://a.b.com/pypi/simple --trusted-host a.b.com fixed it permanent: linux OS: add these in ~/.pip/pip.conf(create it if no exist) [global] index-url = http://a.b.com/pypi/simple [install] trusted-host = a.b.com ps: http://a.b.com/pypi/simple your proxy_http_address
stratum-mining-proxy error - Can't decode message
I'm attempting to run stratum-mining-proxy with minerd. Proxy starts and runs with the following command: python ./mining_proxy.py -o ltc-stratum.kattare.com -p 3333 -pa scrypt Proxy starts fine. Run Minerd (U/P removed): minerd -a scrypt -r 1 -s 6 -o http://127.0.0.1:3333 -O USERNAME.1:PASSWORD Following errors are received. This one from the proxy: 2013-07-18 01:33:59,981 ERROR protocol protocol.dataReceived # Processing of message failed Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/stratum-0.2.12-py2.7.egg/stratum/protocol.py", line 185, in dataReceived self.lineReceived(line, request_counter) File "/usr/local/lib/python2.7/dist-packages/stratum-0.2.12-py2.7.egg/stratum/protocol.py", line 216, in lineReceived raise custom_exceptions.ProtocolException("Cannot decode message '%s'" % line) 'rotocolException: Cannot decode message 'POST / HTTP/1.1 And this from minerd. What am I doing wrong? Any help is appreciated! [2013-07-18 01:33:59] HTTP request failed: Empty reply from server [2013-07-18 01:33:59] json_rpc_call failed, retry after 30 seconds
I am a little curious, I don't know as a fact but I was under the impression that the mining proxy was for BTC not LTC. But anyways I believe I got a similar message when I first installed it as well. To fix, or rather to actually get it running I had to use the Git installation method instead of installing manually. Installation on Linux using Git This is advanced option for experienced users, but give you the easiest way for updating the proxy. 1.git clone git://github.com/slush0/stratum-mining-proxy.git 2.cd stratum-mining-proxy 3.sudo apt-get install python-dev # Development package of Python are necessary 4.sudo python distribute_setup.py # This will upgrade setuptools package 5.sudo python setup.py develop # This will install required dependencies (namely Twisted and Stratum libraries), but don't install the package into the system. 6.You can start the proxy by typing "./mining_proxy.py" in the terminal window. Using default settings, proxy connects to Slush's pool interface. 7.If you want to connect to another pool or change other proxy settings, type "./mining_proxy.py --help". 8.If you want to update the proxy, type "git pull" in the package directory.