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

bugfix: fix async certificate decoding #1085

Merged
merged 1 commit into from
Jul 22, 2022
Merged

Conversation

clundin25
Copy link
Contributor

@clundin25 clundin25 commented Jul 20, 2022

The async _cert_fetch implementation was not properly decoding
certificates into a utf-8 string. This updates the code and tests to
decode the certificates into strings.

Without this fix, the code will raise a ValueError exception, because the data type passed to json.dumps is not expected.

This resolves #1050.

@@ -95,7 +95,7 @@ async def _fetch_certs(request, certs_url):

data = await response.data.read()

return json.loads(json.dumps(data))
return json.loads(data.decode("utf-8"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works )

and a question to @arithmetic1728: I wonder if there is a way we can decode all the responses at the time we get them... so we don't have to remember this next time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be achieved by adding a new decoded_data property in parallel to the data property in the _Response class

@property
def data(self):
return self._response.content

@clundin25 clundin25 force-pushed the main branch 3 times, most recently from 37d2843 to ea58c02 Compare July 21, 2022 16:04
The async `_cert_fetch` implementation was not properly decoding
certificates into a utf-8 string. This updates the code and tests to
decode the certificates into strings.

This resolves googleapis#1050.
@clundin25 clundin25 added the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 22, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 22, 2022
@clundin25 clundin25 merged commit 741c6c6 into googleapis:main Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Async _fetch_certs does not decode certs - TypeError Object of type bytes is not JSON serializable
4 participants