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

Set explicit Accept-Encoding header #61

Merged
merged 1 commit into from
Nov 11, 2023
Merged

Conversation

KapJI
Copy link
Contributor

@KapJI KapJI commented Nov 11, 2023

I found that sometimes urllib3 may add extra headers which can cause NeedsBrowser error. This won't help with BadAuthentication but may help with NeedsBrowser for some users.

This is list of headers urllib3 can set automatically:
https://github.com/urllib3/urllib3/blob/f7cd7f3f632cf5224f627536f02c2abf7e4146d1/src/urllib3/util/request.py#L19

Same host, same terminal tab (same env), same Python (not just version, exactly the same installation), same versions of requests, urllib3, certify, pycryptodomex.
Different virtual envs and terminal tabs.

Working:

Hypertext Transfer Protocol
    POST /auth HTTP/1.1\r\n
    Host: android.clients.google.com\r\n
    Accept-Encoding: identity\r\n
    User-Agent: GoogleAuth/1.4\r\n
    Content-type: application/x-www-form-urlencoded\r\n
    Content-Length: 541\r\n
    \r\n
    [Full request URI: https://android.clients.google.com/auth]
    [HTTP request 1/1]
    [Response in frame: 25]
    File Data: 541 bytes

Failing with NeedsBrowser:

Hypertext Transfer Protocol
    POST /auth HTTP/1.1\r\n
    Host: android.clients.google.com\r\n
    User-Agent: GoogleAuth/1.4\r\n
    Accept-Encoding: gzip, deflate\r\n
    Accept: */*\r\n
    Connection: keep-alive\r\n
    Content-type: application/x-www-form-urlencoded\r\n
    Content-Length: 541\r\n
    \r\n
    [Full request URI: https://android.clients.google.com/auth]
    [HTTP request 1/1]
    [Response in frame: 27]
    File Data: 541 bytes

@KapJI KapJI changed the title Set explicit HTTP headers Set explicit Accept-Encoding header Nov 11, 2023
@simon-weber
Copy link
Owner

Nice find! Thanks!

@simon-weber simon-weber merged commit 93a54f7 into simon-weber:master Nov 11, 2023
2 checks passed
@KapJI KapJI deleted the headers branch November 11, 2023 21:43
@KapJI
Copy link
Contributor Author

KapJI commented Nov 21, 2023

@simon-weber let's make a new release so users can benefit from this fix?

@simon-weber
Copy link
Owner

Released as 1.0.4.

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.

2 participants