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

auth doesn't seem to be used in Client.stream #1256

Closed
2 tasks done
ulodciv opened this issue Sep 4, 2020 · 3 comments · Fixed by #1312
Closed
2 tasks done

auth doesn't seem to be used in Client.stream #1256

ulodciv opened this issue Sep 4, 2020 · 3 comments · Fixed by #1312
Labels
bug Something isn't working

Comments

@ulodciv
Copy link

ulodciv commented Sep 4, 2020

Checklist

  • The bug is reproducible against the latest release: 0.14.3.
  • There are no similar issues or pull requests to fix it yet: that I could find....

Describe the bug

Client.stream seems to not use auth as provided in the initializer of Client objects.

To reproduce

  1. Create an httpx.Client object with auth set.

cli = httpx.Client(auth=("user", "password"))

  1. Check that the client.get/post works ok.
url = "<url to smallish file>"
resp = cli.get(url)
resp.raise_for_status()  # no error is raised
  1. Then try Client.stream normally.
    with cli.stream("GET", url) as resp:
        resp.raise_for_status()  # HTTPStatusError 401 is raised
        ....
  1. Try Client.stream with auth.
    with cli.stream("GET", url, auth=cli.auth) as resp:
        resp.raise_for_status()  # no error is raised
        ....

Expected behavior

auth is used by method Client.stream.

Actual behavior

auth is not used by method Client.stream.

Environment

  • OS:
  • Python version
  • HTTPX version:
Python 3.7.7 (default, May 16 2020, 11:38:23) 
[GCC 10.1.1 20200507 (Red Hat 10.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import httpx
>>> httpx.__version__
'0.14.3'
>>> 
  • Async environment: sync
  • HTTP proxy: no
  • Custom certificates: no
@florimondmanca
Copy link
Member

florimondmanca commented Sep 4, 2020

Hmm — not able to reproduce…

import httpx

client = httpx.Client(auth=("user", "pass"))

with client.stream("GET", "https://httpbin.org/basic-auth/user/pass") as r:
    print(r)  # <Response [200 OK]>

with client.stream("GET", "https://httpbin.org/basic-auth/user/otherpass") as r:
    print(r)  # <Response [401 Unauthorized]> (as expected)

Does the above^ reproduce the issue on your side? If not, what is the host you're requesting exactly? Could be a faulty server implementation… 🤔

@florimondmanca florimondmanca added the needs confirmation The issue described has not yet been confirmed, or replicated locally. label Sep 4, 2020
@enguerranchevalier
Copy link

Hello @florimondmanca / @tomchristie,

With version 0.15.0, I can reproduce the issue. On one of our packages using both the stream function and authentication, we had to make a fix to pass the authentication to the client.stream method directly rather than to the httpx.Client.

Screenshot:

image

@tomchristie
Copy link
Member

Confirmed in #1312

@tomchristie tomchristie added bug Something isn't working and removed needs confirmation The issue described has not yet been confirmed, or replicated locally. labels Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants