Skip to content

TypeError: cannot pickle 'cryptography.hazmat.bindings._rust.openssl.rsa.RSAPublicKey' object #240

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

Closed
akozhikkot opened this issue Apr 8, 2025 · 4 comments
Labels
question Further information is requested

Comments

@akozhikkot
Copy link

While trying to use SingleTenantAzureAuthorizationCodeBearer with FastAPI with the basic settings and following the example guideline, I am getting this error

TypeError: cannot pickle 'cryptography.hazmat.bindings._rust.openssl.rsa.RSAPublicKey' object

From the logs I can see that it has loaded the settings , auth endpoint , issuer etc.

When a request is send with Bearer token, it throws the above error.

I am using python 3.11 and 5.1.1 of the library

File "C:\Program Files\Python311\Lib\copy.py", line 146, in deepcopy
y = copier(x, memo)
^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 206, in _deepcopy_list
append(deepcopy(a, memo))
^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 271, in _reconstruct
state = deepcopy(state, memo)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 146, in deepcopy
y = copier(x, memo)
^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 231, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 271, in _reconstruct
state = deepcopy(state, memo)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 146, in deepcopy
y = copier(x, memo)
^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 231, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 271, in _reconstruct
state = deepcopy(state, memo)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 146, in deepcopy
y = copier(x, memo)
^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 231, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 146, in deepcopy
y = copier(x, memo)
^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 231, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\copy.py", line 161, in deepcopy
rv = reductor(4)
^^^^^^^^^^^
TypeError: cannot pickle 'cryptography.hazmat.bindings._rust.openssl.rsa.RSAPublicKey' object

@akozhikkot akozhikkot added the question Further information is requested label Apr 8, 2025
@JonasKs
Copy link
Member

JonasKs commented Apr 9, 2025

What version of cryptography are you using?

@akozhikkot
Copy link
Author

Hi @JonasKs , the error was due to trying to validate token obtained with graph api scopes. We are able to move past now after configuring the API scope and permissions on the client.

But we are stumbled on an error INFO:fastapi_azure_auth:Token contains invalid claims. Audience doesn't match.

But looking at jwt.io with the access token we can see the audience same as the client id used to configure authentication.

Any suggestions from your side ?

@JonasKs
Copy link
Member

JonasKs commented Apr 9, 2025

The audience should be matching the backend app, not the OpenAPI / frontend app.

Please do the entire tutorial from start to finish again, it should not give any errors.

@JonasKs JonasKs closed this as completed Apr 23, 2025
@JonasKs
Copy link
Member

JonasKs commented Apr 23, 2025

Closing for inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants