jazzband / django-push-notifications

Send push notifications to mobile devices through GCM or APNS in Django.
MIT License
2.24k stars 609 forks source link

Incompatibility issue when upgrading PyJWT >= 2.0.0 by any other package #628

Closed muhammad-mamdouh closed 2 years ago

muhammad-mamdouh commented 2 years ago

When installing any package with PyJWT >= 2.0.0 the server crashes as the django-push-notifications require PyJWT < 2.0.0

Traceback:

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/Users/anon/.pyenv/versions/3.9.0/lib/python3.9/threading.py", line 950, in _bootstrap_inner
    self.run()
  File "/Users/anon/.pyenv/versions/3.9.0/lib/python3.9/threading.py", line 888, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/anon/.virtualenvs/venv/lib/python3.9/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/Users/anon/.virtualenvs/venv/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
    autoreload.raise_last_exception()
  File "/Users/anon/.virtualenvs/venv/lib/python3.9/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
  File "/Users/anon/.virtualenvs/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 375, in execute
    autoreload.check_errors(django.setup)()
  File "/Users/anon/.virtualenvs/venv/lib/python3.9/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/Users/anon/.virtualenvs/venv/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/anon/.virtualenvs/venv/lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "/Users/anon/.virtualenvs/venv/lib/python3.9/site-packages/django/apps/config.py", line 224, in create
    import_module(entry)
  File "/Users/anon/.pyenv/versions/3.9.0/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/anon/.virtualenvs/venv/lib/python3.9/site-packages/push_notifications/__init__.py", line 4, in <module>
    __version__ = pkg_resources.require("django-push-notifications")[0].version
  File "/Users/anon/.virtualenvs/venv/lib/python3.9/site-packages/pkg_resources/__init__.py", line 886, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/Users/anon/.virtualenvs/venv/lib/python3.9/site-packages/pkg_resources/__init__.py", line 777, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (PyJWT 2.3.0 (/Users/anon/.virtualenvs/venv/lib/python3.9/site-packages), Requirement.parse('PyJWT<2.0.0,>=1.4.0'), {'apns2'})
auvipy commented 2 years ago

that package needed to be adjusted IMHO

muhammad-mamdouh commented 2 years ago

@auvipy I figured out now that the problem mainly at the apns2 package and actually its updated there but the maintainer didn't release the master update now.

https://github.com/Pr0Ger/PyAPNs2/issues/133

nik13 commented 2 years ago

this is because the package is not updated on pip. Use github master branch to install the lastest package

madhavSoni commented 2 years ago

Was anyone able to get this to work? I get this issue when I used the latest commit

apns2 @ git+https://github.com/Pr0Ger/PyAPNs2.git@910780bb909c85ffd40f8d2cd517b764c4576253 PyJWT==2.3.0 django-push-notifications==3.0.0

[03/Apr/2022 19:00:54] "PUT /api/changeTransactionStatus/fdf8c2fd-c937-475a-960f-9d8b862db492/ HTTP/1.1" 200 13966
Traceback (most recent call last):
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/handlers.py", line 138, in run
    self.finish_response()
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/handlers.py", line 183, in finish_response
    self.close()
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 114, in close
    super().close()
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/simple_server.py", line 38, in close
    SimpleHandler.close(self)
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/handlers.py", line 321, in close
    self.result.close()
  File "/Users/madhavsoni/Documents/BazarBackend/bazar_backend/api/views/TransactionViews/TransactionView.py", line 168, in close
    self.then_callback()
  File "/Users/madhavsoni/Documents/BazarBackend/bazar_backend/api/views/TransactionViews/TransactionView.py", line 232, in send_push_notification
    badge=lambda token: APNSDevice.objects.get(
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/push_notifications/models.py", line 136, in send_message
    creds=creds, **kwargs
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/push_notifications/apns.py", line 154, in apns_send_bulk_message
    creds=creds, **kwargs
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/push_notifications/apns.py", line 103, in _apns_send
    **notification_kwargs
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/apns2/client.py", line 203, in send_notification_batch
    priority, expiration, collapse_id, push_type)
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/apns2/client.py", line 141, in send_notification_async
    auth_header = self.__credentials.get_authorization_header(topic)
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/apns2/credentials.py", line 60, in get_authorization_header
    token = self._get_or_create_topic_token()
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/apns2/credentials.py", line 90, in _get_or_create_topic_token
    headers=headers)
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/jwt/api_jwt.py", line 63, in encode
    return api_jws.encode(json_payload, key, algorithm, headers, json_encoder)
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/jwt/api_jws.py", line 113, in encode
    key = alg_obj.prepare_key(key)
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/jwt/algorithms.py", line 416, in prepare_key
    key = load_pem_public_key(key)
TypeError: load_pem_public_key() missing 1 required positional argument: 'backend'
[03/Apr/2022 19:00:55] "PUT /api/changeTransactionStatus/fdf8c2fd-c937-475a-960f-9d8b862db492/ HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 51618)
Traceback (most recent call last):
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/handlers.py", line 138, in run
    self.finish_response()
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/handlers.py", line 183, in finish_response
    self.close()
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 114, in close
    super().close()
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/simple_server.py", line 38, in close
    SimpleHandler.close(self)
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/handlers.py", line 321, in close
    self.result.close()
  File "/Users/madhavsoni/Documents/BazarBackend/bazar_backend/api/views/TransactionViews/TransactionView.py", line 168, in close
    self.then_callback()
  File "/Users/madhavsoni/Documents/BazarBackend/bazar_backend/api/views/TransactionViews/TransactionView.py", line 232, in send_push_notification
    badge=lambda token: APNSDevice.objects.get(
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/push_notifications/models.py", line 136, in send_message
    creds=creds, **kwargs
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/push_notifications/apns.py", line 154, in apns_send_bulk_message
    creds=creds, **kwargs
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/push_notifications/apns.py", line 103, in _apns_send
    **notification_kwargs
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/apns2/client.py", line 203, in send_notification_batch
    priority, expiration, collapse_id, push_type)
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/apns2/client.py", line 141, in send_notification_async
    auth_header = self.__credentials.get_authorization_header(topic)
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/apns2/credentials.py", line 60, in get_authorization_header
    token = self._get_or_create_topic_token()
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/apns2/credentials.py", line 90, in _get_or_create_topic_token
    headers=headers)
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/jwt/api_jwt.py", line 63, in encode
    return api_jws.encode(json_payload, key, algorithm, headers, json_encoder)
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/jwt/api_jws.py", line 113, in encode
    key = alg_obj.prepare_key(key)
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/jwt/algorithms.py", line 416, in prepare_key
    key = load_pem_public_key(key)
TypeError: load_pem_public_key() missing 1 required positional argument: 'backend'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/handlers.py", line 141, in run
    self.handle_error()
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 119, in handle_error
    super().handle_error()
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/handlers.py", line 368, in handle_error
    self.finish_response()
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/handlers.py", line 180, in finish_response
    self.write(data)
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/handlers.py", line 274, in write
    self.send_headers()
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/handlers.py", line 331, in send_headers
    if not self.origin_server or self.client_is_modern():
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/handlers.py", line 344, in client_is_modern
    return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/socketserver.py", line 650, in process_request_thread
    self.finish_request(request, client_address)
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/socketserver.py", line 720, in __init__
    self.handle()
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 174, in handle
    self.handle_one_request()
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 197, in handle_one_request
    handler.run(self.server.get_app())
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/handlers.py", line 144, in run
    self.close()
  File "/Users/madhavsoni/eb-virt/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 114, in close
    super().close()
  File "/Users/madhavsoni/.pyenv/versions/3.7.2/lib/python3.7/wsgiref/simple_server.py", line 35, in close
    self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'