infinite recursion on 401 error

I'm using requests 0.7.4, and am having a strange problem with a GET that is digest protected.

The request takes a long time (2-3 minutes) to come back, and when it does, I get this:

hooks.py:38: UserWarning: maximum recursion depth exceeded while calling a Python object
  warnings.warn(str(why))
401
HTTP Digest: Access denied.

The same request works fine in a browser using the same auth credentials.


Ouch — Thanks for the the bug! 


In 0.7.5 "digest" authentication fails for me too.
I am sending a GET request with parameters (against Apache)

If I change line 70 of auth.py from:

```
path = urlparse(r.request.url).path
```

to:

```
path = r.url
```

authentication succeeds.


@osuchw, that makes all of my digest auth endpoints fail. What service are you using?


Unfortunately the service is not public :/.
I believe the file I try to access is served by httpd from busybox.

Comparing the Auth headers generated by 0.6.6 (which works) and 0.7.5 the difference is that 0.6.6 version includes url parameters in the "uri" and 0.7.5 does not.  For example:

0.7.5:
Digest username="FakeUser", realm="Sage Digital ENDEC", nonce="lJq1Tg==24beb53fdc1227725609de6067a97e743b33e2ec", uri="/cgi-bin/logcgi.cgi", response="a2eca1bd05b3aea2a65f506dd3c7b957", algorithm="MD5", qop=auth, nc=00000001, cnonce="79715aa24c676321"

0.6.6
Digest username="FakeUser", realm="Sage Digital ENDEC", nonce="uum1Tg==a95c28cb289c85c35760855764c6dcb991f3da27", uri="/cgi-bin/logcgi.cgi?xmlfile=xml+file&NumRecs=100&StartRec=0", response="a0e4e98576a094412962a9542d994acb", algorithm="MD5", qop=auth, nc=00000001, cnonce="e99903411b95b469"


ah! That'll be simple to fix. Thanks :) 

## 

Kenneth Reitz

On Sunday, November 6, 2011 at 6:45 PM, osuchw wrote:

> Unfortunately the service is not public :/.
> I believe the file I try to access is served by httpd from busybox.
> 
> Comparing the Auth headers generated by 0.6.6 (which works) and 0.7.5 the difference is that 0.6.6 version includes url parameters in the "uri" and 0.7.5 does not. For example:
> 
> 0.7.5:
> Digest username="FakeUser", realm="Sage Digital ENDEC", nonce="lJq1Tg==24beb53fdc1227725609de6067a97e743b33e2ec", uri="/cgi-bin/logcgi.cgi", response="a2eca1bd05b3aea2a65f506dd3c7b957", algorithm="MD5", qop=auth, nc=00000001, cnonce="79715aa24c676321"
> 
> 0.6.6
> Digest username="FakeUser", realm="Sage Digital ENDEC", nonce="uum1Tg==a95c28cb289c85c35760855764c6dcb991f3da27", uri="/cgi-bin/logcgi.cgi?xmlfile=xml+file&NumRecs=100&StartRec=0", response="a0e4e98576a094412962a9542d994acb", algorithm="MD5", qop=auth, nc=00000001, cnonce="e99903411b95b469"
> 
> ---
> 
> Reply to this email directly or view it on GitHub:
> https://github.com/kennethreitz/requests/issues/237#issuecomment-2648588


So should we roll back to 0.6.6 for the time being if we need digest?


@mfeif, Requests v0.7.6 was just released that fixes this :)


The new rev didn't solve my bug... what do you need from me to help track it down?


One thing I discovered is that requests seems to be stripping a query string out of the URL, thus:

url="/testfeed.json?foo=bar"

becomes

url="/testfeed.jsonfoo=bar"

At least as inspected by doing r.request.headers after the failed request comes back.

I confirmed that the feed works if I take off the query strings.

I'll open a new bug; I can't re-open this one.


Any word on this? I don't see another open bug that covers this as indicated by @mfeif. 
I'm bumping up against infinite recursion with 401 responses using digest auth. 

```
File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/api.py", line 98, in put
    return request('put', url, data=data, **kwargs)
  File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/sessions.py", line 279, in request
    resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
  File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/sessions.py", line 374, in send
    r = adapter.send(request, **kwargs)
  File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/adapters.py", line 219, in send
    r = self.build_response(request, resp)
  File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/adapters.py", line 113, in build_response
    response = dispatch_hook('response', req.hooks, response)
  File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/hooks.py", line 39, in dispatch_hook
    _hook_data = hook(hook_data)
  File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/auth.py", line 156, in handle_401
    _r = r.connection.send(r.request)
  File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/adapters.py", line 219, in send
    r = self.build_response(request, resp)
  File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/adapters.py", line 113, in build_response
    response = dispatch_hook('response', req.hooks, response)
  File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/hooks.py", line 39, in dispatch_hook
    _hook_data = hook(hook_data)
  File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/auth.py", line 156, in handle_401
    _r = r.connection.send(r.request)
  File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/adapters.py", line 219, in send
    r = self.build_response(request, resp)
  File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/adapters.py", line 113, in build_response
    response = dispatch_hook('response', req.hooks, response)
  File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/hooks.py", line 39, in dispatch_hook
    _hook_data = hook(hook_data)
  File "/Users/jmakeig/Library/Python/2.7/lib/python/site-packages/requests/auth.py", line 156, in handle_401
```


@jmakeig could you file a new issue for this?