jazzband / django-push-notifications

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

does not work with python 3.10 #675

Closed samirsd closed 1 year ago

uzza1hossain commented 1 year ago

Can you provide additional context?

samirsd commented 1 year ago

when I try to send a push notification I get cannot import name 'Iterable' from 'collections' (/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/__init__.py)

samirsd commented 1 year ago

others have commented on this issue. it seems to be related to unmaintained dependencies, specifically apns2 and hyper I believe.

https://github.com/jazzband/django-push-notifications/issues/583

https://github.com/jazzband/django-push-notifications/issues/622#issuecomment-1331050728

bradleydworak commented 1 year ago

Yes, concur, the incompatibility with Python 3.10 is due to the apns2 and thus hyper dependencies. May need to consider incorporating aioapns as an alternative. Thoughts?

samirsd commented 1 year ago

yes i’ve been using aiopns as a result of these issues actually and it has been working for me

bradleydworak commented 1 year ago

That’s great feedback, thank you. I’m tempted to open another Issue and propose to the group to switch to aioapns and drop apns2 if they aren’t jumping on supporting python 10 by this point in time.

On Wed, Jan 25, 2023 at 10:58 AM Samir @.***> wrote:

yes i’ve been using aiopns as a result of these issues actually and it has been working for me

— Reply to this email directly, view it on GitHub https://github.com/jazzband/django-push-notifications/issues/675#issuecomment-1403841021, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANVBG5P7T2LPFGXHBLZNGLWUFERVANCNFSM6AAAAAASPHUOH4 . You are receiving this because you commented.Message ID: @.***>

bradleydworak commented 1 year ago

@samirsd Did you encounter an issue with aioapns complaining that it is expecting an EllipticCurve PrivateKey/PublicKey pair? If so, could you tell me what you did to resolve the issue, or point me to a online reference? I have the APNS cert/key pem file already.

samirsd commented 1 year ago

@bradleydworak I didn't encounter that issue but I've been using it in sandbox mode

Maybe double check the steps for generating your .p8 file?

my code looks like this:

` async def send_message(device_token, message): key_path = os.path.join(settings.BASE_DIR, "path/to/my/AuthKey_12345ABC.p8") use_sandbox = True

apns_key_client = APNs(
    key= key_path,
    key_id=KEY_ID,
    team_id=TEAM_ID,
    topic=IOS_APP_BUNDLE_ID,  # Bundle ID
    use_sandbox=use_sandbox,
)
request = NotificationRequest(
    device_token=device_token,
    message = {
        "aps": {
            "alert": message,
            "badge": "1",
        }
    },
    notification_id=str(uuid4()),  # optional
    time_to_live=3,                # optional
    push_type=PushType.ALERT,      # optional             # optional
)
await apns_key_client.send_notification(request)

`

I did however encounter an issue where aioapns would send repeated push notifications so I just commented out the retry logic as follows: https://github.com/samirsd/aioapns/commit/f7e6081da214b426930a8a5bf8fe25a2f4433f52

bradleydworak commented 1 year ago

Thx for the feedback. Yes I wasn’t able to find any documentation on generating the .p8 file, and unclear if it is derived from the APNS cert/key or generated separately. Do you have a link to instructions and/or sample code on how to do this? I’m hoping to add some documentation to the aioapns Readme once I understand this better.

On Sat, Feb 4, 2023 at 9:21 PM Samir @.***> wrote:

@bradleydworak https://github.com/bradleydworak I didn't encounter that issue but I've been using it in sandbox mode

Maybe double check the steps for generating your .p8 file?

my code looks like this:

`async def send_message(device_token, message): key_path = os.path.join(settings.BASE_DIR, "path/to/my/AuthKey_12345ABC.p8") use_sandbox = True

apns_key_client = APNs( key= key_path, key_id=KEY_ID, team_id=TEAM_ID, topic=IOS_APP_BUNDLE_ID, # Bundle ID use_sandbox=use_sandbox, ) request = NotificationRequest( device_token=device_token, message = { "aps": { "alert": message, "badge": "1", } }, notification_id=str(uuid4()), # optional time_to_live=3, # optional push_type=PushType.ALERT, # optional # optional ) await apns_key_client.send_notification(request)

`

I did however encounter an issue where aioapns would send repeated push notifications so I just commented out the retry logic as follows: @.*** https://github.com/samirsd/aioapns/commit/f7e6081da214b426930a8a5bf8fe25a2f4433f52

— Reply to this email directly, view it on GitHub https://github.com/jazzband/django-push-notifications/issues/675#issuecomment-1416903531, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANVBG4JZTJD32KU34IOX5LWV4FCJANCNFSM6AAAAAASPHUOH4 . You are receiving this because you were mentioned.Message ID: @.***>

samirsd commented 1 year ago

It has to be done from the apple developer website https://stackoverflow.com/questions/44631803/ios-swift-how-to-create-p8-file

`Certificates, Identifiers & Profiles > Keys > Click "+" > Check Apple Push Notifications service (APNs)

Choose a name, then register it. It will give you an option to download the p8 file.`

bradleydworak commented 1 year ago

Thx…finally got it working. Without any documentation it wasn’t clear that you use either the key or the cert file but not both. I’m hoping to make a pull request and forgo apns.

On Sun, Feb 5, 2023 at 9:46 AM Samir @.***> wrote:

It has to be done from the apple developer website https://stackoverflow.com/questions/44631803/ios-swift-how-to-create-p8-file

— Reply to this email directly, view it on GitHub https://github.com/jazzband/django-push-notifications/issues/675#issuecomment-1417990976, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANVBG2RXI6KMCLR6UELAWDWV64KZANCNFSM6AAAAAASPHUOH4 . You are receiving this because you were mentioned.Message ID: @.***>

samirsd commented 1 year ago

no prob glad i could help

AsimDawrat commented 1 year ago

Any fork you know which uses aioapns?

azmeuk commented 1 year ago

Closing in favor of #622