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

JsonDecodeError when decoding response for gmail messages.get method #496

Closed
niconicoj opened this issue May 9, 2024 · 4 comments · Fixed by #507
Closed

JsonDecodeError when decoding response for gmail messages.get method #496

niconicoj opened this issue May 9, 2024 · 4 comments · Fixed by #507

Comments

@niconicoj
Copy link

niconicoj commented May 9, 2024

Hi,

I am using the google-gmail1 crate and trying to get the content of some mail by making a messages.get call but it fails at the decoding step with the following message (I cut the message short since it contains some sensitive info) :

GmailApiError(JsonDecodeError("{\n  \"id\": \"18f5dc3c6c373405\",\n  \"threadId\": \"18f5dc3c6c373405\",\n  \"labelIds\": [\n    \"Label_5088752233975968583\",\n    \"IMPORTANT\",\n    \"CATEGORY_PERSONAL\",\n    \"INBOX\"\n  ],\n  \"snippet\": [...] }\n      }\n    ]\n  },\n  \"sizeEstimate\": 46682,\n  \"historyId\": \"73834\",\n  \"internalDate\": \"1715265050000\"\n}\n", Error("Invalid byte 45, offset 271.", line: 134, column: 9)))

Digging into the error it seems it fails to decode the data part of the MessagePartBody which is said to be base64url.

I looked around and found a bunch of issues related to this. I also found issue #446 which I understand is supposed to be a fix for this kind of problem. Unfortunately it does not seems like it works for this request. Maybe it even broke it since it seems the fix replaced the previous urlsafe_base64 decoder with the standard_base64 altogether.

Is this analysis correct ? Are there any ideas on how to fix the issue ?

@Byron
Copy link
Owner

Byron commented May 10, 2024

Thanks for reporting. The problem is that some endpoints need URLsafe base64, others need the normal one and it's unclear which one to pick by looking at the API description. At least that's the assumption right now, which is why either way it's going to be wrong for some.

@paolobarbolini
Copy link
Contributor

I've just encountered this same issue. Would it be possible to infer it from the documentation?

@paolobarbolini
Copy link
Contributor

I'm trying to navigate through how the project works and it looks possible. For example https://gmail.googleapis.com/$discovery/rest?version=v1 mentions base64url and standard base64 in the description

@paolobarbolini
Copy link
Contributor

I've opened #507 with a fix for this

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

Successfully merging a pull request may close this issue.

3 participants