Python -> requests Connection fails with "certificate verify failed" - python

I'm trying to connect to JIRA using a Python wrapper for the Rest interface and I can't get it to work at all. I've read everything I could find so this is my last resort.
I've tried a lot of stuff including
verify=False
but nothing has worked so far.
The strange thing is that with urllib.request it does work without any SSL cert (it's just some internal cert) but the goal is to use the Python Jira wrapper so it's not really an option...
I've tried Python 3.4 and 2.7... getting desperate...
Any ideas?
The code is very simple:
import requests
r = requests.get('https://jiratest.myurl.com/rest/api/2/serverInfo')
print(r.content)
Error:
C:\Python34\python.exe C:/projects/jirascriptsx/delete_worklogs.py
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 544, in urlopen
body=body, headers=headers)
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 341, in _make_request
self._validate_conn(conn)
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 761, in _validate_conn
conn.connect()
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connection.py", line 238, in connect
ssl_version=resolved_ssl_version)
File "C:\Python34\lib\site-packages\requests\packages\urllib3\util\ssl_.py", line 279, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Python34\lib\ssl.py", line 365, in wrap_socket
_context=self)
File "C:\Python34\lib\ssl.py", line 583, in __init__
self.do_handshake()
File "C:\Python34\lib\ssl.py", line 810, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\requests\adapters.py", line 370, in send
timeout=timeout
File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 574, in urlopen
raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/projects/jirascriptsx/delete_worklogs.py", line 4, in <module>
r = requests.get('https://jiratest.uniqa.at/rest/api/2/serverInfo')
File "C:\Python34\lib\site-packages\requests\api.py", line 69, in get
return request('get', url, params=params, **kwargs)
File "C:\Python34\lib\site-packages\requests\api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "C:\Python34\lib\site-packages\requests\sessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python34\lib\site-packages\requests\sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "C:\Python34\lib\site-packages\requests\adapters.py", line 431, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
Process finished with exit code 1

There is a problem with our infrastructure which seems to bring out a bug in the requests module where the SSL verification ignore flag doesn't work properly.
None of the solutions offered in any of the Stackoverflow posts worked.
As a workaround I'm running the code directly on the server.

If you have certificate file(Certificate.pem) and key file(Key.pem) then we can authenticate like this
cert=/path/to/certificate_file
key_file=/path/to/key_file
url=https://jiratest.myurl.com/rest/api/2/serverInfo
with requests.session() as session:
session.cert=(cert,key_file)
session.auth=(username,base64.urlsafe_b64decode(password))
response=session.get(url)
if response.status_code == 200:
json_data = response.json()

Related

Acumos model onboarding python CLI

I'm trying to onboard a simple python model from CLI as shown in the related tutorial.
After providing the onboarding token (user:api-token) I'm getting the error below.
The Acumos platform has been deployed using the AIO tools using prep-deploy process.
I was able to dump the same model and onboard using the web UI.
Traceback (most recent call last):
File "/home/gprato/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 677, in urlopen
chunked=chunked,
File "/home/gprato/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "/home/gprato/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 978, in _validate_conn
conn.connect()
File "/home/gprato/.local/lib/python3.6/site-packages/urllib3/connection.py", line 371, in connect
ssl_context=context,
File "/home/gprato/.local/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 384, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/lib/python3.6/ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "/usr/lib/python3.6/ssl.py", line 817, in __init__
self.do_handshake()
File "/usr/lib/python3.6/ssl.py", line 1077, in do_handshake
self._sslobj.do_handshake()
File "/usr/lib/python3.6/ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/gprato/.local/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/gprato/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 727, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/home/gprato/.local/lib/python3.6/site-packages/urllib3/util/retry.py", line 439, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='***', port=443): Max retries exceeded with url: /onboarding-app/v2/models (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "simple_example.py", line 16, in <module>
session.push(model, 'example-2')
File "/home/gprato/.local/lib/python3.6/site-packages/acumos/session.py", line 103, in push
_push_model(dump_dir, self.push_api, self.auth_api, options, extra_headers=extra_headers)
File "/home/gprato/.local/lib/python3.6/site-packages/acumos/session.py", line 172, in _push_model
_post_model(files, push_api, auth_api, tries, max_tries, extra_headers, options)
File "/home/gprato/.local/lib/python3.6/site-packages/acumos/session.py", line 192, in _post_model
resp = requests.post(push_api, files=files, headers=headers)
File "/home/gprato/.local/lib/python3.6/site-packages/requests/api.py", line 119, in post
return request('post', url, data=data, json=json, **kwargs)
File "/home/gprato/.local/lib/python3.6/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/home/gprato/.local/lib/python3.6/site-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "/home/gprato/.local/lib/python3.6/site-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "/home/gprato/.local/lib/python3.6/site-packages/requests/adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='***', port=443): Max retries exceeded with url: /onboarding-app/v2/models (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),))
UPDATE
I've solved by adding the following line into the python script:
os.environ['CURL_CA_BUNDLE'] = ""
In addition to that I also had to change the push url ("acumos/onboarding-app/v2/models") as it was wrongly reported in the acumos python client library ("acumos/onboarding-app/v2/push").
I recomend you to add the following in your python script
os.environ['CURL_CA_BUNDLE'] = ""
it will skip the certificate verification

SSL error after "download" call from yfinance

I installed yfinance in Spyder (Python 3.7) but when I make a basic call, such as:
import yfinance as yf
df_yahoo = yf.download('AAPL',
start='2000-01-01',
end='2010-12-31',
progress=False)
print(df_yahoo)
I get an error message:
Exception in thread Thread-9: Traceback (most recent call last):
File
"c:\users\miniconda3\lib\site-packages\urllib3\connectionpool.py",
line 672, in urlopen
chunked=chunked, File "c:\users/miniconda3\lib\site-packages\urllib3\connectionpool.py",
line 376, in _make_request
self._validate_conn(conn) File "c:\users\miniconda3\lib\site-packages\urllib3\connectionpool.py",
line 994, in validate_conn
conn.connect() File "c:\users\miniconda3\lib\site-packages\urllib3\connection.py",
line 360, in connect
ssl_context=context, File "c:\users\miniconda3\lib\site-packages\urllib3\util\ssl.py",
line 370, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname) File "c:\users\miniconda3\lib\ssl.py", line 423, in
wrap_socket
session=session File "c:\users\miniconda3\lib\ssl.py", line 870, in _create
self.do_handshake() File "c:\users\miniconda3\lib\ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed
certificate in certificate chain (_ssl.c:1076)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"c:\users\miniconda3\lib\site-packages\requests\adapters.py",
line 449, in send
timeout=timeout File "c:\users\miniconda3\lib\site-packages\urllib3\connectionpool.py",
line 720, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2] File
"c:\users\miniconda3\lib\site-packages\urllib3\util\retry.py",
line 436, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError:
HTTPSConnectionPool(host='query1.finance.yahoo.com', port=443): Max
retries exceeded with url:
/v8/finance/chart/AAPL?period1=946681200&period2=1293750000&interval=1d&includePrePost=False&events=div%2Csplits
(Caused by SSLError(SSLCertVerificationError(1, '[SSL:
CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed
certificate in certificate chain (_ssl.c:1076)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"c:\users\miniconda3\lib\threading.py", line 926, in
_bootstrap_inner
self.run() File "c:\users\miniconda3\lib\threading.py", line 870, in run
self._target(*self._args, **self.kwargs) File "c:\users\miniconda3\lib\site-packages\multitasking_init.py",
line 102, in _run_via_pool
return callee(*args, **kwargs) File "c:\users\miniconda3\lib\site-packages\yfinance\multi.py",
line 167, in _download_one_threaded
actions, period, interval, prepost, proxy, rounding) File "c:\users\miniconda3\lib\site-packages\yfinance\multi.py",
line 182, in _download_one
rounding=rounding, many=True) File "c:\users\miniconda3\lib\site-packages\yfinance\base.py",
line 150, in history
data = _requests.get(url=url, params=params, proxies=proxy) File "c:\users\miniconda3\lib\site-packages\requests\api.py",
line 76, in get
return request('get', url, params=params, **kwargs) File "c:\users\miniconda3\lib\site-packages\requests\api.py",
line 61, in request
return session.request(method=method, url=url, **kwargs) File "c:\users\miniconda3\lib\site-packages\requests\sessions.py",
line 530, in request
resp = self.send(prep, **send_kwargs) File "c:\users\miniconda3\lib\site-packages\requests\sessions.py",
line 643, in send
r = adapter.send(request, **kwargs) File "c:\users\miniconda3\lib\site-packages\requests\adapters.py",
line 514, in send
raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='query1.finance.yahoo.com', port=443): Max
retries exceeded with url:
/v8/finance/chart/AAPL?period1=946681200&period2=1293750000&interval=1d&includePrePost=False&events=div%2Csplits
(Caused by SSLError(SSLCertVerificationError(1, '[SSL:
CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed
certificate in certificate chain (_ssl.c:1076)')))
Moreover, Spyder seems to get stuck in some sort of loop and I have to manually interrupt it.
Can anyone help me here?
Many thanks
I believe the problem comes from an external source, maybe Yahoo Finance was down? I tried running your code and it works fine for me. (PyCharm, Python 3.7)
On MacOS Big Sur, You need to install the certificate in Python 3.9.
cd /Applications/Python\ 3.9/
./Install\ Certificates.command

python proxy request can't fetch data from www.google.com

I use Shadowsocks to get out from the Chinese GFW. It works fine when I use chrome to browse www.google.com.
Recently I am learning something about python crawlers, and I want to fetch data from www.google.com by using request.
I learned that I have to set proxy to get out from the GFW, and the code is like
import socket
import socks
import requests
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 1080)
socket.socket = socks.socksocket
print(requests.get('http://ifconfig.me/ip').text)
and then I get the address of my Shadowsocks server
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /Users/lsongseven/PycharmProjects/wordcloud/cl.py
52.73.41.9
and here is my Shadowsocks configuration
enter image description here
However, when I use this script to fetch data from google, it doesn't work anymore
import socket
import socks
import requests
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 1080)
socket.socket = socks.socksocket
print(requests.get('https://www.google.com/').text)
Here is the error message:
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /Users/lsongseven/PycharmProjects/wordcloud/cl.py
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/urllib3/connectionpool.py", line 346, in _make_request
self._validate_conn(conn)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/urllib3/connectionpool.py", line 850, in _validate_conn
conn.connect()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/urllib3/connection.py", line 326, in connect
ssl_context=context)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/urllib3/util/ssl_.py", line 329, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 376, in wrap_socket
_context=self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 747, in __init__
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 983, in do_handshake
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 628, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:646)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/urllib3/util/retry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:646)'),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/lsongseven/PycharmProjects/wordcloud/cl.py", line 7, in <module>
print(requests.get('https://www.google.com/').text)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/adapters.py", line 506, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:646)'),))
So the problem is that Shadowsocks works fine but the python script cannot work, does anyone have some suggestions?
"SSLEOFError" Seems like OpenSSL cause this prolbem.
You may try to upgrade your OpenSSL viesion,or reinstall OpenSSl.

Geolocation-python package produces SSL Error on Windows 7

Using Python 3.4, I installed the below geolocation package
https://pypi.python.org/pypi/geolocation-python/0.2.2
I tested it in IDLE using the code below
key = 'myGoogleKey'
google = GoogleMaps(api_key=key)
addr = 'Boston MA'
location = google.search(location=addr)
it fails at the last line, generating an SSL Error
Traceback (most recent call last):
File "c:\python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 559, in urlopen
body=body, headers=headers)
File "c:\python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 345, in _make_request
self._validate_conn(conn)
File "c:\python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 782, in _validate_conn
conn.connect()
File "c:\python34\lib\site-packages\requests\packages\urllib3\connection.py", line 250, in connect
ssl_version=resolved_ssl_version)
File "c:\python34\lib\site-packages\requests\packages\urllib3\util\ssl_.py", line 285, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "c:\python34\lib\ssl.py", line 365, in wrap_socket
_context=self)
File "c:\python34\lib\ssl.py", line 583, in __init__
self.do_handshake()
File "c:\python34\lib\ssl.py", line 810, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\python34\lib\site-packages\requests\adapters.py", line 370, in send
timeout=timeout
File "c:\python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 588, in urlopen
raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
location = google.search(location=addr)
File "c:\python34\lib\site-packages\geolocation\main.py", line 18, in search
return self.geocode.search(location, lat, lng)
File "c:\python34\lib\site-packages\geolocation\geocode\main.py", line 48, in search
data = self.client.get_data(address=address, latitude=latitude, longitude=longitude)
File "c:\python34\lib\site-packages\geolocation\geocode\client.py", line 40, in get_data
return self.send_data(self.API_URL, self.query_parameters)
File "c:\python34\lib\site-packages\geolocation\client.py", line 22, in send_data
response = requests.get(url, params=params)
File "c:\python34\lib\site-packages\requests\api.py", line 69, in get
return request('get', url, params=params, **kwargs)
File "c:\python34\lib\site-packages\requests\api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "c:\python34\lib\site-packages\requests\sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "c:\python34\lib\site-packages\requests\sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "c:\python34\lib\site-packages\requests\adapters.py", line 433, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
I used this same package and code using python 2.7 in a linux environment and it worked fine. Any ideas on how I can fix this?

python requests ssl error 550

I've been trying to login to site using python 3.3 and requests, but I couldn't get that far. When ever i try to go to that page I get unknown _ssl.c:550 error. Google and other pages work just fine.
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 478, in urlopen
body=body, headers=headers)
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 285, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Python33\lib\http\client.py", line 1065, in request
self._send_request(method, url, body, headers)
File "C:\Python33\lib\http\client.py", line 1103, in _send_request
self.endheaders(body)
File "C:\Python33\lib\http\client.py", line 1061, in endheaders
self._send_output(message_body)
File "C:\Python33\lib\http\client.py", line 906, in _send_output
self.send(msg)
File "C:\Python33\lib\http\client.py", line 844, in send
self.connect()
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connection.py", line 95, in connect
ssl_version=resolved_ssl_version)
File "C:\Python33\lib\site-packages\requests\packages\urllib3\util.py", line 634, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Python33\lib\ssl.py", line 245, in wrap_socket
_context=self)
File "C:\Python33\lib\ssl.py", line 345, in __init__
raise x
File "C:\Python33\lib\ssl.py", line 341, in __init__
self.do_handshake()
File "C:\Python33\lib\ssl.py", line 548, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL] unknown error (_ssl.c:550)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\requests\adapters.py", line 324, in send
timeout=timeout
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 502, in urlopen
raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: [SSL] unknown error (_ssl.c:550)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Tomas\Documents\Dropbox\python\web_login.py", line 8, in <module>
page = requests.get(url, verify=False)
File "C:\Python33\lib\site-packages\requests\api.py", line 55, in get
return request('get', url, **kwargs)
File "C:\Python33\lib\site-packages\requests\api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python33\lib\site-packages\requests\sessions.py", line 382, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python33\lib\site-packages\requests\sessions.py", line 485, in send
r = adapter.send(request, **kwargs)
File "C:\Python33\lib\site-packages\requests\adapters.py", line 379, in send
raise SSLError(e)
requests.exceptions.SSLError: [SSL] unknown error (_ssl.c:550)
Here is script I tried.
import requests
url = "https://klevas.vu.lt/"
page = requests.get(url, verify=False)
print (page.content)
Changing url to https://www.klevas.vu.lt (added www) results in different error: class 'socket.gaierror'>: [Errno 11004]
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 478, in urlopen
body=body, headers=headers)
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 285, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Python33\lib\http\client.py", line 1065, in request
self._send_request(method, url, body, headers)
File "C:\Python33\lib\http\client.py", line 1103, in _send_request
self.endheaders(body)
File "C:\Python33\lib\http\client.py", line 1061, in endheaders
self._send_output(message_body)
File "C:\Python33\lib\http\client.py", line 906, in _send_output
self.send(msg)
File "C:\Python33\lib\http\client.py", line 844, in send
self.connect()
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connection.py", line 73, in connect
timeout=self.timeout,
File "C:\Python33\lib\socket.py", line 417, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11004] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\requests\adapters.py", line 324, in send
timeout=timeout
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 528, in urlopen
raise MaxRetryError(self, url, e)
requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.klevas.vu.lt', port=443): Max retries exceeded with url: / (Caused by <class 'socket.gaierror'>: [Errno 11004] getaddrinfo failed)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Tomas\Documents\Dropbox\python\web_login.py", line 7, in <module>
page = requests.get(url, verify=False)
File "C:\Python33\lib\site-packages\requests\api.py", line 55, in get
return request('get', url, **kwargs)
File "C:\Python33\lib\site-packages\requests\api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python33\lib\site-packages\requests\sessions.py", line 382, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python33\lib\site-packages\requests\sessions.py", line 485, in send
r = adapter.send(request, **kwargs)
File "C:\Python33\lib\site-packages\requests\adapters.py", line 372, in send
raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.klevas.vu.lt', port=443): Max retries exceeded with url: / (Caused by <class 'socket.gaierror'>: [Errno 11004] getaddrinfo failed)
Example to what #sigmavirus24 meant:
(It's taken literally from the the linked blog post, only PROTOCOL_SSLv3 is used
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_SSLv3)
s = requests.Session()
s.mount('https://', MyAdapter())
print(s.get('https://klevas.vu.lt/'))
The server you are talking to is an application server from oracle. When searching for it's server identificator you get links to a lot of bugtrackers of open source projects running into this bug -.-
This seems to be an issue with openssl which is what Python's ssl module relies on (and which in turn requests relies on). The way to verify this is by using the openssl s_client command to check this:
~/sandbox/requests (master) openssl s_client -connect klevas.vu.lt:443
CONNECTED(00000003)
140721982121664:error:140773E8:SSL routines:SSL23_GET_SERVER_HELLO:reason(1000):s23_clnt.c:741:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 319 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
---
That's the same error I see when testing this on python 2.7.
Furthermore, if I test the second url www.kleavs.vu.lt I get this:
~/sandbox/requests (master) openssl s_client -connect www.klevas.vu.lt:443
connect: Connection refused
connect:errno=111
Which is the same thing I see when I try to request the second URL via requests on either Python 2 or 3.
This is not an issue with requests but similar bugs have been filed: #606 (which is where I pulled the openssl command).
You can attempt to follow the instructions here to determine if a different version of TLS or SSL will fix this for you, but I'm not sure it will help in this case.
The solution from t-8ch misses the promised link.
This solution need extra modules which were neither described nor linked.
I found that at least with Xubuntu 14.04 you need to install these modules to get the code running:
a. python3-requests (http://github.com/kennethreitz/requests)
b. python3-urllib3 (http://urllib3.readthedocs.org/en/latest)
Then I needed to modify the code a little bit:
from urllib3.poolmanager import PoolManager
rather than
from requests.packages.urllib3.poolmanager import PoolManager
import requests
from requests.adapters import HTTPAdapter
from 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_SSLv3)
s = requests.Session()
s.mount('https://', MyAdapter())
print(s.get('https://klevas.vu.lt/'))
returns
<Response [200]>

Categories