Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue Oct 4, 2022 · 7 comments
Labels

Comments

@Sphinix1
Copy link

Sphinix1 commented Oct 4, 2022

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
Copy link
Contributor

@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?

@DMRobertson DMRobertson changed the title binascii.Error Unexplained binascii.Error: Invalid base64-encoded string: number of data characters (157) cannot be 1 more than a multiple of 4 Oct 4, 2022
@Sphinix1
Copy link
Author

Sphinix1 commented Oct 4, 2022 via email

@squahtx
Copy link
Contributor

squahtx commented Oct 5, 2022

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
Copy link
Author

Sphinix1 commented Oct 5, 2022

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 squahtx changed the title Unexplained binascii.Error: Invalid base64-encoded string: number of data characters (157) cannot be 1 more than a multiple of 4 binascii.Error: Invalid base64-encoded string: number of data characters (157) cannot be 1 more than a multiple of 4 when using FluffyChat Oct 6, 2022
@squahtx
Copy link
Contributor

squahtx commented Oct 6, 2022

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.

@vanyasem
Copy link

@squahtx FluffyChat was built to work with krille-chan/fluffygate to be exact, and it's the Push Gateway running on https://push.fluffychat.im/ which is the default gateway FluffyChat uses.

However, the incompatibility point still stands. There's also #319 which was refused to be addressed by both parties: famedly/matrix-dart-sdk#1947, famedly/matrix-dart-sdk#1948

@vanyasem
Copy link

Also see #301 and #344

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants