{"action":"created","issue":{"url":"https://api.github.com/repos/kennethreitz/requests/issues/2481","labels_url":"https://api.github.com/repos/kennethreitz/requests/issues/2481/labels{/name}","comments_url":"https://api.github.com/repos/kennethreitz/requests/issues/2481/comments","events_url":"https://api.github.com/repos/kennethreitz/requests/issues/2481/events","html_url":"https://github.com/kennethreitz/requests/issues/2481","id":60481079,"number":2481,"title":"\"407 Proxy Authentication Required\" after redirect with load balanced authenticated proxies","user":{"login":"gsakkis","id":291289,"avatar_url":"https://avatars.githubusercontent.com/u/291289?v=3","gravatar_id":"","url":"https://api.github.com/users/gsakkis","html_url":"https://github.com/gsakkis","followers_url":"https://api.github.com/users/gsakkis/followers","following_url":"https://api.github.com/users/gsakkis/following{/other_user}","gists_url":"https://api.github.com/users/gsakkis/gists{/gist_id}","starred_url":"https://api.github.com/users/gsakkis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gsakkis/subscriptions","organizations_url":"https://api.github.com/users/gsakkis/orgs","repos_url":"https://api.github.com/users/gsakkis/repos","events_url":"https://api.github.com/users/gsakkis/events{/privacy}","received_events_url":"https://api.github.com/users/gsakkis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-10T10:49:14Z","updated_at":"2015-03-10T11:30:00Z","closed_at":null,"body":"I'm having a problem I traced down to requests as the equivalent curl command works. I am running HAProxy on `localhost:5555` to load balance requests to a pool of authenticated backend http proxies as explained [here](http://serverfault.com/questions/386431/authenticated-proxies-on-haproxy-load-balancer). It works fine for fetching urls without redirection, as shown below using [httpie](https://github.com/jakubroztocil/httpie) (same behaviour observed using requests directly from the shell):\r\n```\r\n$ http 'http://httpbin.org/get' --proxy http:http://localhost:5555 --headers --debug \r\nHTTPie 0.9.2\r\nHTTPie data: /home/gsakkis/.httpie\r\nRequests 2.5.3\r\nPygments 2.0.2\r\nPython 2.7.6 (default, Mar 22 2014, 22:59:56) \r\n[GCC 4.8.2] linux2\r\n\r\n>>> requests.request({'allow_redirects': False,\r\n 'auth': None,\r\n 'cert': None,\r\n 'data': OrderedDict(),\r\n 'files': DataDict(),\r\n 'headers': {'User-Agent': 'HTTPie/0.9.2'},\r\n 'method': 'get',\r\n 'params': ParamsDict(),\r\n 'proxies': {u'http': u'http://localhost:5555'},\r\n 'stream': True,\r\n 'timeout': 30,\r\n 'url': u'http://httpbin.org/get',\r\n 'verify': True})\r\n\r\nHTTP/1.0 200 OK\r\nAccess-Control-Allow-Credentials: true\r\nAccess-Control-Allow-Origin: *\r\nConnection: keep-alive\r\nContent-Length: 269\r\nContent-Type: application/json\r\nDate: Tue, 10 Mar 2015 10:38:37 GMT\r\nServer: nginx\r\nVia: 1.0 fl291 (squid/3.1.10)\r\nX-Cache: MISS from fl291\r\nX-Cache-Lookup: MISS from fl291:80\r\n```\r\n\r\nIf I fetch a url that redirects without actually redirecting it still works, returning 302:\r\n```\r\n$ http 'http://httpbin.org/redirect-to?url=http://example.com/' --proxy http:http://localhost:5555 --headers --debug\r\nHTTPie 0.9.2\r\nHTTPie data: /home/gsakkis/.httpie\r\nRequests 2.5.3\r\nPygments 2.0.2\r\nPython 2.7.6 (default, Mar 22 2014, 22:59:56) \r\n[GCC 4.8.2] linux2\r\n\r\n>>> requests.request({'allow_redirects': False,\r\n 'auth': None,\r\n 'cert': None,\r\n 'data': OrderedDict(),\r\n 'files': DataDict(),\r\n 'headers': {'User-Agent': 'HTTPie/0.9.2'},\r\n 'method': 'get',\r\n 'params': ParamsDict(),\r\n 'proxies': {u'http': u'http://localhost:5555'},\r\n 'stream': True,\r\n 'timeout': 30,\r\n 'url': u'http://httpbin.org/redirect-to?url=http://example.com/',\r\n 'verify': True})\r\n\r\nHTTP/1.0 302 Moved Temporarily\r\nAccess-Control-Allow-Credentials: true\r\nAccess-Control-Allow-Origin: *\r\nConnection: keep-alive\r\nContent-Length: 0\r\nContent-Type: text/html; charset=utf-8\r\nDate: Tue, 10 Mar 2015 10:41:00 GMT\r\nLocation: http://example.com/\r\nServer: nginx\r\nVia: 1.0 mf5 (squid/3.1.10)\r\nX-Cache: MISS from mf5\r\nX-Cache-Lookup: MISS from mf5:80\r\n```\r\n\r\nHowever attempting to follow the redirect fails with 407:\r\n```\r\n$ http 'http://httpbin.org/redirect-to?url=http://example.com/' --proxy http:http://localhost:5555 --headers --follow --debug\r\nHTTPie 0.9.2\r\nHTTPie data: /home/gsakkis/.httpie\r\nRequests 2.5.3\r\nPygments 2.0.2\r\nPython 2.7.6 (default, Mar 22 2014, 22:59:56) \r\n[GCC 4.8.2] linux2\r\n\r\n>>> requests.request({'allow_redirects': True,\r\n 'auth': None,\r\n 'cert': None,\r\n 'data': OrderedDict(),\r\n 'files': DataDict(),\r\n 'headers': {'User-Agent': 'HTTPie/0.9.2'},\r\n 'method': 'get',\r\n 'params': ParamsDict(),\r\n 'proxies': {u'http': u'http://localhost:5555'},\r\n 'stream': True,\r\n 'timeout': 30,\r\n 'url': u'http://httpbin.org/redirect-to?url=http://example.com/',\r\n 'verify': True})\r\n\r\nHTTP/1.0 407 Proxy Authentication Required\r\nConnection: keep-alive\r\nContent-Length: 4\r\nContent-Type: text/html\r\nDate: Tue, 10 Mar 2015 10:42:02 GMT\r\nMime-Version: 1.0\r\nProxy-Authenticate: Basic realm=\"login\"\r\nServer: squid/3.1.10\r\nVia: 1.0 mf5 (squid/3.1.10)\r\nX-Cache: MISS from mf5\r\nX-Cache-Lookup: NONE from mf5:80\r\nX-Squid-Error: ERR_CACHE_ACCESS_DENIED 0\r\n```\r\n\r\nThe equivalent curl command seems to work fine though:\r\n```\r\n$ curl 'http://httpbin.org/redirect-to?url=http://example.com/' -s -L -x localhost:5555 -v -o /dev/null\r\n* Hostname was NOT found in DNS cache\r\n*   Trying 127.0.0.1...\r\n* Connected to localhost (127.0.0.1) port 5555 (#0)\r\n> GET http://httpbin.org/redirect-to?url=http://example.com/ HTTP/1.1\r\n> User-Agent: curl/7.35.0\r\n> Host: httpbin.org\r\n> Accept: */*\r\n> Proxy-Connection: Keep-Alive\r\n> \r\n* HTTP 1.0, assume close after body\r\n< HTTP/1.0 302 Moved Temporarily\r\n< Server: nginx\r\n< Date: Tue, 10 Mar 2015 10:44:56 GMT\r\n< Content-Type: text/html; charset=utf-8\r\n< Content-Length: 0\r\n< Location: http://example.com/\r\n< Access-Control-Allow-Origin: *\r\n< Access-Control-Allow-Credentials: true\r\n< X-Cache: MISS from fl291\r\n< X-Cache-Lookup: MISS from fl291:80\r\n< Via: 1.0 fl291 (squid/3.1.10)\r\n* HTTP/1.0 connection set to keep alive!\r\n< Connection: keep-alive\r\n< \r\n* Connection #0 to host localhost left intact\r\n* Issue another request to this URL: 'http://example.com/'\r\n* Hostname was found in DNS cache\r\n*   Trying 127.0.0.1...\r\n* Connected to localhost (127.0.0.1) port 5555 (#1)\r\n> GET http://example.com/ HTTP/1.0\r\n> User-Agent: curl/7.35.0\r\n> Host: example.com\r\n> Accept: */*\r\n> Proxy-Connection: Keep-Alive\r\n> \r\n* HTTP 1.0, assume close after body\r\n< HTTP/1.0 200 OK\r\n< Accept-Ranges: bytes\r\n< Cache-Control: max-age=604800\r\n< Content-Type: text/html\r\n< Date: Tue, 10 Mar 2015 10:44:57 GMT\r\n< ETag: \"359670651\"\r\n< Expires: Tue, 17 Mar 2015 10:44:57 GMT\r\n< Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT\r\n< Server: ECS (cpm/F9D5)\r\n< X-Cache: HIT\r\n< x-ec-custom-error: 1\r\n< Content-Length: 1270\r\n< X-Cache: MISS from bv400\r\n< X-Cache-Lookup: MISS from bv400:80\r\n< Via: 1.0 bv400 (squid/3.1.10)\r\n* HTTP/1.0 connection set to keep alive!\r\n< Connection: keep-alive\r\n< \r\n{ [data not shown]\r\n* Connection #1 to host localhost left intact\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/kennethreitz/requests/issues/comments/78036568","html_url":"https://github.com/kennethreitz/requests/issues/2481#issuecomment-78036568","issue_url":"https://api.github.com/repos/kennethreitz/requests/issues/2481","id":78036568,"user":{"login":"gsakkis","id":291289,"avatar_url":"https://avatars.githubusercontent.com/u/291289?v=3","gravatar_id":"","url":"https://api.github.com/users/gsakkis","html_url":"https://github.com/gsakkis","followers_url":"https://api.github.com/users/gsakkis/followers","following_url":"https://api.github.com/users/gsakkis/following{/other_user}","gists_url":"https://api.github.com/users/gsakkis/gists{/gist_id}","starred_url":"https://api.github.com/users/gsakkis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gsakkis/subscriptions","organizations_url":"https://api.github.com/users/gsakkis/orgs","repos_url":"https://api.github.com/users/gsakkis/repos","events_url":"https://api.github.com/users/gsakkis/events{/privacy}","received_events_url":"https://api.github.com/users/gsakkis/received_events","type":"User","site_admin":false},"created_at":"2015-03-10T11:30:00Z","updated_at":"2015-03-10T11:30:00Z","body":"I have played with it occasionally but I'm far from an expert. Any particular command line I could try?"}}