Created
December 17, 2022 08:36
-
-
Save shc261392/6bea0e723949d21cebfaa5a76616c72c to your computer and use it in GitHub Desktop.
A script to reproduce the issue that binary data is lost when using httpx client with authlib 1.2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from io import BytesIO | |
from authlib.integrations.requests_client import OAuth1Session | |
from authlib.integrations.httpx_client import OAuth1Client | |
CLIENT_ID = 'mockClientId' | |
CLIENT_SECRET = 'mockClientSecret' | |
ENDPOINT = 'http://localhost:8000' | |
requests_client = OAuth1Session(CLIENT_ID, CLIENT_SECRET) | |
httpx_client = OAuth1Client(CLIENT_ID, CLIENT_SECRET) | |
mock_file = BytesIO() | |
mock_file.write(b'foobar') | |
mock_file.seek(0) | |
print('Uploading file via authlib requests client') | |
r = requests_client.post(ENDPOINT, files={'file': mock_file}) | |
mock_file.seek(0) | |
print('Uploading file via authlib httpx client') | |
g = httpx_client.post(ENDPOINT, files={'file': mock_file}) |
requests client
Received header Content-Length: 146
Received actual bytes: 146
127.0.0.1 - - [17/Dec/2022 08:39:09] "POST / HTTP/1.1" 200 -
httpx client
Received header Content-Length: 0
Received actual bytes: 0
127.0.0.1 - - [17/Dec/2022 08:39:09] "POST / HTTP/1.1" 200 -
It's obvious the binary data are lost when using httpx client.
The issue itself has nothing to do with OAuth-related implementations or OAuth tokens/signatures. Therefore no need to use any real OAuth client id/secret or implement any OAuth mechanism on server side.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a simple local HTTP server for debugging. Should be helpful for debugging/reproducing the issue.