matrix-org / sygnal

Sygnal: reference Push Gateway for Matrix
Apache License 2.0
164 stars 147 forks source link

`binascii.Error: Invalid base64-encoded string: number of data characters (157) cannot be 1 more than a multiple of 4` when using FluffyChat #325

Closed Sphinix1 closed 2 years ago

Sphinix1 commented 2 years ago

Hi , can anyone help be solve this error ?

matrix-sygnal[116160]: binascii.Error: Invalid base64-encoded string: number of data characters (157) cannot be 1 more than a multiple of 4

DMRobertson commented 2 years ago

@reivilibre responded in the Sygnal room.

sounds like https://github.com/matrix-org/sygnal/blob/main/docs/troubleshooting.md#common-cause-1-hex-rather-than-base64-encoding — you need to base64 encode your token rather than hex encode

is this on startup or when sending a push?

Sphinix1 commented 2 years ago

It’s during push

Sent from my iPhone

On 4 Oct 2022, at 12:42, David Robertson @.***> wrote:

 @reivilibre responded in the Sygnal room.

sounds like https://github.com/matrix-org/sygnal/blob/main/docs/troubleshooting.md#common-cause-1-hex-rather-than-base64-encoding — you need to base64 encode your token rather than hex encode

is this on startup or when sending a push?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

squahtx commented 2 years ago

Can you please post the full stack trace and explain your setup? Are you using Synapse to talk to Sygnal or are you doing something else? Which Matrix client are you using and what modifications have you made?

Sphinix1 commented 2 years ago

fluffychat yes synapse to sygnal

Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: File "/usr/local/lib/python3.7/site-packages/sygnal/http.py", line 275, in _handle_dispatch Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: result = await pushkin.dispatch_notification(notif, d, context) Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: File "/usr/local/lib/python3.7/site-packages/sygnal/notifications.py", line 217, in dispatch_notification Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: return await self._dispatch_notification_unlimited(n, device, context) Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: File "/usr/local/lib/python3.7/site-packages/sygnal/apnspushkin.py", line 347, in _dispatch_notification_unlimited Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: log, span, device, shaved_payload, prio Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: File "/usr/local/lib/python3.7/site-packages/sygnal/apnspushkin.py", line 245, in _dispatch_request Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: device_token = base64.b64decode(device.pushkey).hex() Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: File "/usr/local/lib/python3.7/base64.py", line 87, in b64decode Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: return binascii.a2b_base64(s) Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: binascii.Error: Invalid base64-encoded string: number of data characters (157) cannot be 1 more than a multiple of 4 Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: 2022-10-05 19:03:39,233 [1] ERROR sygnal.http [c009397b-3664-4203-ac63-31053f28a481] Exception whilst dispatching notification. Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: Traceback (most recent call last): Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: File "/usr/local/lib/python3.7/site-packages/sygnal/http.py", line 275, in _handle_dispatch Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: result = await pushkin.dispatch_notification(notif, d, context) Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: File "/usr/local/lib/python3.7/site-packages/sygnal/notifications.py", line 217, in dispatch_notification Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: return await self._dispatch_notification_unlimited(n, device, context) Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: File "/usr/local/lib/python3.7/site-packages/sygnal/apnspushkin.py", line 347, in _dispatch_notification_unlimited Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: log, span, device, shaved_payload, prio Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: File "/usr/local/lib/python3.7/site-packages/sygnal/apnspushkin.py", line 245, in _dispatch_request Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: device_token = base64.b64decode(device.pushkey).hex() Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: File "/usr/local/lib/python3.7/base64.py", line 87, in b64decode Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: return binascii.a2b_base64(s) Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: binascii.Error: Invalid base64-encoded string: number of data characters (157) cannot be 1 more than a multiple of 4 Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: 2022-10-05 19:03:39,235 [1] INFO sygnal.access Handled request: "144.214.4.183" - - [05/Oct/2022:19:03:39 +0000] "POST /_matrix/push/v1/notify HTTP/1.0" 500 - "-" "Synapse/1.68.0" Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: 2022-10-05 19:03:39,235 [1] INFO sygnal.access Handled request: "144.214.4.183" - - [05/Oct/2022:19:03:39 +0000] "POST /_matrix/push/v1/notify HTTP/1.0" 500 - "-" "Synapse/1.68.0" Oct 05 19:03:39 fluffychat matrix-sygnal[754590]: 2022-10-05 19:03:39,235 [1] INFO sygnal.access Handled request: "144.214.4.183" - - [05/Oct/2022:19:03:39 +0000] "POST /_matrix/push/v1/notify HTTP/1.0" 500 - "-" "Synapse/1.68.0"

squahtx commented 2 years ago

Thanks. As @reivilibre has previously mentioned, https://github.com/matrix-org/sygnal/blob/main/docs/troubleshooting.md#common-cause-1-hex-rather-than-base64-encoding is the issue.

There is an implicit coupling between clients and the push gateway. FluffyChat was built to work with https://gitlab.com/famedly/services/famedly-push-gateway, not Sygnal. To make FluffyChat work with Sygnal, the code in lib/utils/background_push.dart needs to be modified to base64-encode the push token.