SSLError when using requests.session
Summary.
Getting a SSLError while using requests.session to send a POST Request. OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to dev.domain.nl:443 When using requests sessions to connect to a https url , requests throws a SSLError
Some background
- I have not added any certificates
- The project works locally but after deployment to kubernetes, from inside the container - the post request is not being sent to the url
- verify=false does not work either
What I am using: Python 2.7.12 Flask==0.12.2 Kubernetes requests latest
Expected Result
Get HTTP Response code 200 after sending a POST request
Actual Result
Traceback (most recent call last): File "/usr/local/lib/python2.7/threading.py", line 801, in __bootstrap_inner self.run() File "/usr/local/lib/python2.7/threading.py", line 1073, in run self.function(*self.args, **self.kwargs) File "app.py", line 136, in main generatePost() File "app.py", line 127, in generatePost resp = testlibrary.test_post() File "/web/testlibrary.py", line 138, in test_post response = sess.post(url, headers= header, params= getpara, data= json.dumps(data),verify=False) File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 559, in post return self.request('POST', url, data=data, json=json, **kwargs) File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 512, in request resp = self.send(prep, **send_kwargs) File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 622, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 511, in send raise SSLError(e, request=request) SSLError: HTTPSConnectionPool(host='dev.domain.nl', port=443): Max retries exceeded with url: /ingestion?LrnDevEui=0059AC0000152A03&LrnFPort=1&LrnInfos=TWA_100006356.873.AS-1-135680630&AS_ID=testserver&Time=2018-06-22T11%3A41%3A08.163%2B02%3A00&Token=1765b08354dfdec (Caused by SSLError(SSLEOFError(8, u'EOF occurred in violation of protocol (_ssl.c:661)'),))
Reproduction Steps
``
import requests
from flask import Flask, request, jsonify
from requests import Request, Session
sess = requests.Session()
adapter = requests.adapters.HTTPAdapter(max_retries = 200)
sess.mount('http://', adapter)
sess.mount('https://', adapter)
sess.cert ='/usr/local/lib/python2.7/site-packages/certifi/cacert.pem'
def test_post():
url = 'https://dev.domain.nl/ingestion/?'
header = {'Content-Type': 'application/json', 'Accept': 'application/json'}
response = sess.post(url, headers= header, params= somepara, data= json.dumps(data))
print response.status_code
return response.status_code
def main():
threading.Timer(10.0, main).start()
test_post()
if __name__ == '__main__':
main()
app.run(host="0.0.0.0", debug=True, port=5001, threaded=True)
System Info
Python 2.7.12 Flask==0.12.2 Kubernetes
@Lukasa Do you think you can help me? :)
Hi there! Thanks for opening this issue. Unfortunately, it seems this is a request for help instead of a report of a defect in the project. Please use StackOverflow for general usage questions instead and only report defects here.
As indicated by
Caused by SSLError(SSLEOFError(8, u'EOF occurred in violation of protocol (_ssl.c:661)')
This is not a Requests bug. Something about your container networking is causing this violation of the protocol.