Skip to content

Error : Web push send from python backend #149

@cmesas

Description

@cmesas

Hello, I'm having a problem when I try to run a notification, I think I'm following the documentation to the letter.

Information

Keys generated with vpaid (python): https://github.com/web-push-libs/vapid/tree/main/python

  • The keys that I indicate are for testing...

PrivateKey [private_key.pem]
----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg4zLDHdp8DtxtcAO4
MZVGeyp2JLJyVrqaMII75nGeAC+hRANCAATW1506jo86/0Ek72wj/AYgGZ6d1R3i
wabGfNb7DlMSmIrdYbrgLLI6HgnszgCGM1ORilZ95RoW9x0ER8+h8SI2
-----END PRIVATE KEY-----

ApplicationServerKey:
BNbXnTqOjzr_QSTvbCP8BiAZnp3VHeLBpsZ81vsOUxKYit1huuAssjoeCezOAIYzU5GKVn3lGhb3HQRHz6HxIjY

Subscription (chrome client: successfully generated with the ApplicationServerKey):
{"endpoint":"https://fcm.googleapis.com/fcm/send/eN9gFAJxIeA:APA91bGRifdlYB8pDgJ9wEYNxxIrVkT5Lb2cNTvtiU55-0bFmV4KGVBuIYbk67NRPjflK4FFdA5tJBPtHVaMMV0IzLrDvBtpBy1cd5VDzrKjXbBN5rJ5NWF-RurzHaFX2iBiun_ypzCT","expirationTime":null,"keys":{"p256dh":"BD9sOH3XIEbgk1x_KvtLbCLvyYEnuQ972W4LaTUnvl_-7vB_q8IzToFKGWK_QaTtUhWBj-Tb556xPuR9uXmr6-E","auth":"X0Zy2i_2WC3tkjElaK3D2g"}}

Code
webpush(
vapid_private_key="private_key.pem",
vapid_claims={"sub": "mailto:contact@example.com"},
subscription_info=subscription,
data=data
)

Error
...
return base64.urlsafe_b64decode(data + b"===="[len(data) % 4:])
File "/usr/lib/python3.8/base64.py", line 133, in urlsafe_b64decode
return b64decode(s)
File "/usr/lib/python3.8/base64.py", line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding

@jrconlin Could you tell me what I may be doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions