You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
This is in regards to the pubsub module. When I send a test message with data "testing 1 2 3" from the web console to a simple python application it fails to decode the message and throws a
binascii.Error: Incorrect padding
Error from
File "/python3.5/site-packages/google/cloud/pubsub/message.py", line 88, in from_api_repr
data = base64.b64decode(api_repr.get('data', b''))
File "/lib/python3.5/base64.py", line 88, in b64decode
I get the same error if I send the same message using the Go libraries.
I do not get the error if I send the message using python however.
All I'm doing is receiving and printing out the messages.
I was using the Google Cloud console to do so by clicking on the publish button. I also did it using the Go library I'll get you the code for that later today.
Here is what the go code looks like, we sent the data "testing 1 2 3" .
I would also add that "testing 1 2 3 4" works fine so I'm guessing its something to do with how other languages pad the base64 encoded bytestring. Maybe you can do something like this,
@daspecster I'd guess this is our problem too. It seems like we ASSUME that base64 values are properly padded but other libraries may strip padding to reduce payload size?
@daspecster sorry for the confusion, I don't think I explained the problem properly.
I have done some further testing, if I send the same message using the Google Console the Go Library will correctly return me the message. So I'm guessing it is being base64 encoded at the server receiving the POST request. As for the Go library I took a quick peek at their source code and it is base64 encoding the payload before sending it off to pubsub. I believe @dhermes is right and other languages strip off the padding to save space. If the console wasn't base64 encoding the message at all Go would also fail with an error.
At this point its pretty dangerous to pass messages from non-python code to python.
👍 this seems to be an issue related to the Cloud Console - but the Python Library should handle this more gracefully. Looks like the proposed fix by @daspecster would handle it.
@Teddy-Schmitz I just merged a partial fix to this issue.
It's important to note that you'll need to base64 encode the message before pasting it into console.cloud.google.com as it just sends the raw data instead of following the API spec.
Activity
dhermes commentedon Oct 7, 2016
Can you give some code snippets indicating how you do this? Thanks.
Teddy-Schmitz commentedon Oct 8, 2016
I was using the Google Cloud console to do so by clicking on the publish button. I also did it using the Go library I'll get you the code for that later today.
Teddy-Schmitz commentedon Oct 8, 2016
Here is what the go code looks like, we sent the data "testing 1 2 3" .
I would also add that "testing 1 2 3 4" works fine so I'm guessing its something to do with how other languages pad the base64 encoded bytestring. Maybe you can do something like this,
http://stackoverflow.com/questions/2941995/python-ignore-incorrect-padding-error-when-base64-decoding
To check for incorrect padding and add them in as necessary?
daspecster commentedon Oct 8, 2016
@Teddy-Schmitz, this is actually the github repository for the Google Cloud Python library.
In your Go example(which I'm not super familiar with Go just FYI), it appears that you may need to cast
datato bytes.See:
The issue's for
google-cloud-goare here https://github.com/GoogleCloudPlatform/google-cloud-go/issues.@omaray, do you know who to contact about this being an issue in the console?
dhermes commentedon Oct 8, 2016
@daspecster I'd guess this is our problem too. It seems like we ASSUME that base64 values are properly padded but other libraries may strip padding to reduce payload size?
Fix pubsub errors when receiving unencoded message. googleapis#2513.
daspecster commentedon Oct 8, 2016
@dhermes, oh I see. For some reason I dove head first into the Go code. (Go is intriguing).
@Teddy-Schmitz sorry about that, I think I understand the problem better now.
It appears that the console is sending message data that is not base64 encoded at all.
The docs for GRPC and REST say that...
See: https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#pubsubmessage
So I guess it's 'assumed' that you should base64 encode your message before typing/pasting it in the console?
I have a branch with a fix(if you can call it that) but I think the right solution is to talk to the console.cloud.google.com/cloudpubsub people.
Teddy-Schmitz commentedon Oct 9, 2016
@daspecster sorry for the confusion, I don't think I explained the problem properly.
I have done some further testing, if I send the same message using the Google Console the Go Library will correctly return me the message. So I'm guessing it is being base64 encoded at the server receiving the POST request. As for the Go library I took a quick peek at their source code and it is base64 encoding the payload before sending it off to pubsub. I believe @dhermes is right and other languages strip off the padding to save space. If the console wasn't base64 encoding the message at all Go would also fail with an error.
At this point its pretty dangerous to pass messages from non-python code to python.
sturench commentedon Oct 11, 2016
👍 this seems to be an issue related to the Cloud Console - but the Python Library should handle this more gracefully. Looks like the proposed fix by @daspecster would handle it.
daspecster commentedon Oct 11, 2016
OK great, I'll get that rolling then!
Fix pubsub errors when receiving unencoded message. googleapis#2513.
tseaver commentedon Oct 12, 2016
FWIW, stripping off the padding to "save bandwidth" is utterly bogus for a JSON-based protocol.
Fix pubsub errors when receiving unencoded message. googleapis#2513.
daspecster commentedon Oct 12, 2016
@Teddy-Schmitz I just merged a partial fix to this issue.
It's important to note that you'll need to base64 encode the message before pasting it into console.cloud.google.com as it just sends the raw data instead of following the API spec.
Thanks for reporting!
Fix pubsub errors when receiving unencoded message. googleapis#2513.
Fix pubsub errors when receiving unencoded message. #2513.
feat: add `df.bigquery` pandas accessor (#2513)
chore: librarian release pull request: 20260316T210518Z (#2520)