Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requests Version MisMatchError #371

Open
lakkireddysatheeshreddy opened this issue Oct 20, 2023 · 1 comment
Open

Requests Version MisMatchError #371

lakkireddysatheeshreddy opened this issue Oct 20, 2023 · 1 comment
Labels
Bug Pull Request Welcome Project would be willing to review a pr to fix this Unconfirmed

Comments

@lakkireddysatheeshreddy
Copy link

lakkireddysatheeshreddy commented Oct 20, 2023

_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
Copy link
Collaborator

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

@sigmavirus24 sigmavirus24 added Unconfirmed Bug Pull Request Welcome Project would be willing to review a pr to fix this labels Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Pull Request Welcome Project would be willing to review a pr to fix this Unconfirmed
Projects
None yet
Development

No branches or pull requests

2 participants