Skip to content

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

Closed

Description

@ulodciv

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

Activity

  1. florimondmanca commented on Sep 4, 2020

    @florimondmanca
    Contributor

    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… 🤔

  2. enguerranchevalier commented on Sep 23, 2020

    @enguerranchevalier

    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

  3. lovelydinosaur commented on Sep 23, 2020

    @lovelydinosaur
    Member

    Confirmed in #1312

  4. added
    bugSomething isn't working
    and removed
    needs confirmationThe issue described has not yet been confirmed, or replicated locally.
    on Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions