I am new to Python requests and come across IOError:[Errno 22] Invalid argumentwhen trying requests.get(). In short, I'm trying to connect to an internal web application using SSL, and therefore pass the cert / key combination in the Requests documentation.
I spent a lot of time exploring potential problems and saw some mention of potential SNI problems, but I am not good enough to find out how I can solve the problem (again, new for queries). Appreciate any push in the right direction / where to dig further (I guess the part of urllib3?)
My code
import requests
cert_file_path = "/Users/me/Documents/cert.pem"
key_file_path = "/Users/me/Documents/key.pem"
url = "https://mydomain/path/to/something"
cert = (cert_file_path, key_file_path)
r = requests.get(url, cert=cert)
My mistake
IOError Traceback (most recent call last)
<ipython-input-48-1ee4a7f23d00> in <module>()
4 url = "https://mydomain/path/to/something"
5 cert = (cert_file_path, key_file_path)
/Users/me/anaconda/lib/python2.7/site-packages/requests/api.pyc in get(url, **kwargs)
66
67 kwargs.setdefault('allow_redirects', True)
69
70
/Users/me/anaconda/lib/python2.7/site-packages/requests/api.pyc in request(method, url, **kwargs)
48
49 session = sessions.Session()
51
52
/Users/me/anaconda/lib/python2.7/site-packages/requests/sessions.pyc in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
462 }
463 send_kwargs.update(settings)
465
466 return resp
/Users/me/anaconda/lib/python2.7/site-packages/requests/sessions.pyc in send(self, request, **kwargs)
574
575
577
578
/Users/me/anaconda/lib/python2.7/site-packages/requests/adapters.pyc in send(self, request, stream, timeout, verify, cert, proxies)
368 decode_content=False,
369 retries=self.max_retries,
371 )
372
/Users/me/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyc in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, **response_kw)
542 httplib_response = self._make_request(conn, method, url,
543 timeout=timeout_obj,
545
546
/Users/me/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyc in _make_request(self, conn, method, url, timeout, **httplib_request_kw)
339
340 try:
342 except (SocketTimeout, BaseSSLError) as e:
343
/Users/me/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.pyc in _validate_conn(self, conn)
760
761 if not getattr(conn, 'sock', None):
763
764 if not conn.is_verified:
/Users/me/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/connection.pyc in connect(self)
236 ca_certs=self.ca_certs,
237 server_hostname=hostname,
239
240 if self.assert_fingerprint:
/Users/me/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.pyc in ssl_wrap_socket(sock, keyfile, certfile, cert_reqs, ca_certs, server_hostname, ssl_version, ciphers, ssl_context)
261 raise
262 if certfile:
264 if HAS_SNI:
265 return context.wrap_socket(sock, server_hostname=server_hostname)
IOError: [Errno 22] Invalid argument
Environment
Python: Python 2.7.11 :: Anaconda 2.4.1 (x86_64)
Requests: 2.6.0
Mac OSX: Yosemite (10.10.5)