Requests Version MisMatchError
Opened this issue · 1 comments
lakkireddysatheeshreddy commented
_main__:1: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography. The next release of cryptography will remove support for Python 3.6.
from cryptography.hazmat.primitives.serialization import Encoding, PrivateFormat, NoEncryption
from cryptography.hazmat.backends import default_backend
from requests_toolbelt.adapters.x509 import X509Adapter
p12_file = '/u01/cdwh/mdm/certificates/cdws_SLDC_Cloud_Connectivity_klb/UserCloudAuth.p12'
pkcs12_password_bytes = "cdws@123".encode('utf8')
backend = default_backend()
with open(p12_file, 'rb') as pkcs12_file:
pkcs12_data = pkcs12_file.read()
def formatJson(responseBytes):
print(json.dumps(json.loads(responseBytes.decode("utf-8")), indent=4, separators=(',', ': '), sort_keys=True))
pycaP12 = load_key_and_certificates(pkcs12_data, pkcs12_password_bytes, backend)
cert_bytes = pycaP12[1].public_bytes(Encoding.DER)
pk_bytes = pycaP12[0].private_bytes(Encoding.DER, PrivateFormat.PKCS8, NoEncryption())
adapter = X509Adapter(max_retries=3, cert_bytes=cert_bytes, pk_bytes=pk_bytes, encoding=Encoding.DER)
Error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/aissys/.local/lib/python3.6/site-packages/requests_toolbelt/adapters/x509.py", line 87, in __init__
self._check_version()
File "/home/aissys/.local/lib/python3.6/site-packages/requests_toolbelt/adapters/x509.py", line 144, in _check_version
requests.__version__
requests_toolbelt.exceptions.VersionMismatchError: The X509Adapter requires at least Requests 2.12.0 to be installed. Version 2.20.0 was found instead.
>>> adapter = X509Adapter(max_retries=3, cert_bytes=cert_bytes, pk_bytes=pk_bytes, encoding=Encoding.DER)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/aissys/.local/lib/python3.6/site-packages/requests_toolbelt/adapters/x509.py", line 87, in __init__
self._check_version()
File "/home/aissys/.local/lib/python3.6/site-packages/requests_toolbelt/adapters/x509.py", line 144, in _check_version
requests.__version__
requests_toolbelt.exceptions.VersionMismatchError: The X509Adapter requires at least Requests 2.12.0 to be installed. Version 2.20.0 was found instead.
I have latest versions installed. The starnge thing here is its saying 2.20 is installed which is not latest.
I am using below versions:
Current versions:
pip show requests
requests: 2.20.0
pip show requests-toolbelt
requests-toolbelt: 1.0.0
pip show pyopenssl
pyopenssl:23.2.0
pip show cryptography
cryptography:40.0.2
sigmavirus24 commented
I suspect we're not able to find the PyOpenSSL Context object
https://github.com/requests/toolbelt/blob/master/requests_toolbelt/adapters/x509.py#L129-L137
Our exception message should be clarified probably but your system still seems to not have what we need for us to support the X509 adapter properly