ValueError: Could not deserialize key data.
See original GitHub issueWhen I try to encode this data:
{'user_id': 19, 'aud': 'django', 'exp': datetime.datetime(2018, 4, 19, 16, 6, 0, 516545), 'email': 'allan.nava@ies-italia.it', 'token': {'expires_in': 300, 'not-before-policy': 1523627965, 'token_type': 'bearer', 'access_token': 'eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICI4c2RZTEJsdFVWTjlqcUpBLXFVWHJmUnRkWXFqanRQX0NRUlhDdHZNU1JVIn0.eyJqdGkiOiJkMDhiN2Q2My1lMmRjLTRiM2MtYjM0MC1kMmNlYTEzY2IyYzMiLCJleHAiOjE1MjQxNTM5NTMsIm5iZiI6MCwiaWF0IjoxNTI0MTUzNjUzLCJpc3MiOiJodHRwOi8vbG9naW4ubGl2ZXJlcG9ydGVyLmNvbTo4MDgwL2F1dGgvcmVhbG1zL3Rhc2NvdXQiLCJhdWQiOiJ0YXNjb3V0Iiwic3ViIjoiZTY5MTNjNGMtNGQ3My00M2EzLWE0NjYtMjE1YmExMzhlNmJlIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoidGFzY291dCIsImF1dGhfdGltZSI6MCwic2Vzc2lvbl9zdGF0ZSI6IjgzZmZhOWQ5LTZhYTQtNGZkNS05MTRlLWIzZDMwZTY5NjNmMyIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOltdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsiZGphbmdvX3N1cGVydXNlciIsIm1lbWJlciIsImFkbWluIiwidW1hX2F1dGhvcml6YXRpb24iLCJzdXBlcnVzZXIiXX0sInJlc291cmNlX2FjY2VzcyI6eyJ3ZWJhcHAiOnsicm9sZXMiOlsibWVtYmVyIiwiY29hY2giXX0sInJlYWxtLW1hbmFnZW1lbnQiOnsicm9sZXMiOlsidmlldy1pZGVudGl0eS1wcm92aWRlcnMiLCJ2aWV3LXJlYWxtIiwibWFuYWdlLWlkZW50aXR5LXByb3ZpZGVycyIsImltc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3LXVzZXJzIiwidmlldy1jbGllbnRzIiwibWFuYWdlLWF1dGhvcml6YXRpb24iLCJtYW5hZ2UtY2xpZW50cyIsInF1ZXJ5LWdyb3VwcyJdfSwiYnJva2VyIjp7InJvbGVzIjpbInJlYWQtdG9rZW4iXX0sImFjY291bnQiOnsicm9sZXMiOlsibWFuYWdlLWFjY291bnQiLCJtYW5hZ2UtYWNjb3VudC1saW5rcyIsInZpZXctcHJvZmlsZSJdfX19.UxInKGZmC1jTcLcW1UyWvQJRDK-UWQU_xEGLq1x22OHj0qopOkywYe4lqXQ2xXaw5MWJtEo1aHpvNFo60CAx1S9fG_GvWShVUNSkG5Q4XlR3kTXWEksuDCf9tQ3oGRr-lRuRmJ6UmoPpI87AHN6I-5mg9xG04hOWjjXPo65-Qdeg8wsThyIO1orARxajWwiP3cnyM_IS3kCEkVu-0Voa47etXvRwSaudaKq21XCrNSWC4W80p7CcRjw1H6_J-nuhP-6iMpE55uYpE4M8VsCFUb4ef0OX-7wXhL0u03WLMA6Yb1zkjGbgpDY7nwIoeEhQinLwVw_-0AMh2NpsXDmt4w', 'refresh_expires_in': 1800}, 'username': 'allannava'}
I got this error:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
response = self._get_response(request)
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.5/dist-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/rest_framework/views.py", line 489, in dispatch
response = self.handle_exception(exc)
File "/usr/local/lib/python3.5/dist-packages/rest_framework/views.py", line 449, in handle_exception
self.raise_uncaught_exception(exc)
File "/usr/local/lib/python3.5/dist-packages/rest_framework/views.py", line 486, in dispatch
response = handler(request, *args, **kwargs)
File "/home/ies/bootcamp/bootcamp/api/views.py", line 221, in post
if serializer.is_valid():
File "/usr/local/lib/python3.5/dist-packages/rest_framework/serializers.py", line 237, in is_valid
self._validated_data = self.run_validation(self.initial_data)
File "/usr/local/lib/python3.5/dist-packages/rest_framework/serializers.py", line 435, in run_validation
value = self.validate(value)
File "/home/ies/bootcamp/bootcamp/api/serializers.py", line 214, in validate
'token': jwt_encode_handler(payload),
File "/home/ies/bootcamp/bootcamp/api/serializers.py", line 103, in jwt_encode_handler
api_settings.JWT_ALGORITHM
File "/usr/local/lib/python3.5/dist-packages/jwt/api_jwt.py", line 56, in encode
json_payload, key, algorithm, headers, json_encoder
File "/usr/local/lib/python3.5/dist-packages/jwt/api_jws.py", line 102, in encode
key = alg_obj.prepare_key(key)
File "/usr/local/lib/python3.5/dist-packages/jwt/algorithms.py", line 207, in prepare_key
key = load_pem_public_key(key, backend=default_backend())
File "/usr/local/lib/python3.5/dist-packages/cryptography/hazmat/primitives/serialization.py", line 24, in load_pem_public_key
return backend.load_pem_public_key(data)
File "/usr/local/lib/python3.5/dist-packages/cryptography/hazmat/backends/openssl/backend.py", line 1032, in load_pem_public_key
self._handle_key_loading_error()
File "/usr/local/lib/python3.5/dist-packages/cryptography/hazmat/backends/openssl/backend.py", line 1283, in _handle_key_loading_error
raise ValueError("Could not deserialize key data.")
ValueError: Could not deserialize key data.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:13
- Comments:8
Top GitHub Comments
Same problem.
Same problem 😞