{"action":"opened","issue":{"url":"https://api.github.com/repos/kennethreitz/requests/issues/3529","repository_url":"https://api.github.com/repos/kennethreitz/requests","labels_url":"https://api.github.com/repos/kennethreitz/requests/issues/3529/labels{/name}","comments_url":"https://api.github.com/repos/kennethreitz/requests/issues/3529/comments","events_url":"https://api.github.com/repos/kennethreitz/requests/issues/3529/events","html_url":"https://github.com/kennethreitz/requests/issues/3529","id":172528973,"number":3529,"title":"Timeout After 301 Redirect Works Strangely","user":{"login":"haydenth","id":1082756,"avatar_url":"https://avatars.githubusercontent.com/u/1082756?v=3","gravatar_id":"","url":"https://api.github.com/users/haydenth","html_url":"https://github.com/haydenth","followers_url":"https://api.github.com/users/haydenth/followers","following_url":"https://api.github.com/users/haydenth/following{/other_user}","gists_url":"https://api.github.com/users/haydenth/gists{/gist_id}","starred_url":"https://api.github.com/users/haydenth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haydenth/subscriptions","organizations_url":"https://api.github.com/users/haydenth/orgs","repos_url":"https://api.github.com/users/haydenth/repos","events_url":"https://api.github.com/users/haydenth/events{/privacy}","received_events_url":"https://api.github.com/users/haydenth/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-22T19:03:29Z","updated_at":"2016-08-22T19:03:29Z","closed_at":null,"body":"Hello friends! Having a small issue with timeouts from URLs after they throw us an HTTP 301 to a bad address. Here's an example script and what happens when I run it (hopefully the offending URL remains offending for you to test, I do not own the domain)\r\n\r\n```\r\nimport requests\r\nimport logging\r\n\r\nlogging.basicConfig(level=logging.INFO)\r\n\r\nurl = 'https://blog.uplabs.com/feed'\r\nreq = requests.get(url, timeout=1)\r\n```\r\n\r\nThen I run this:\r\n```\r\nThomass-MacBook-Air ~/bug $ time python test.py\r\nINFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): blog.uplabs.com\r\nINFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): blog.uplabs.com\r\nTraceback (most recent call last):\r\n  File \"test.py\", line 7, in <module>\r\n    req = requests.get(url, timeout=1)\r\n  File \"/usr/local/lib/python2.7/site-packages/requests/api.py\", line 70, in get\r\n    return request('get', url, params=params, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/requests/api.py\", line 56, in request\r\n    return session.request(method=method, url=url, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/requests/sessions.py\", line 475, in request\r\n    resp = self.send(prep, **send_kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/requests/sessions.py\", line 617, in send\r\n    history = [resp for resp in gen] if allow_redirects else []\r\n  File \"/usr/local/lib/python2.7/site-packages/requests/sessions.py\", line 177, in resolve_redirects\r\n    **adapter_kwargs\r\n  File \"/usr/local/lib/python2.7/site-packages/requests/sessions.py\", line 596, in send\r\n    r = adapter.send(request, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/requests/adapters.py\", line 479, in send\r\n    raise ConnectTimeout(e, request=request)\r\nrequests.exceptions.ConnectTimeout: HTTPConnectionPool(host='blog.uplabs.com', port=3001): Max retries exceeded with url: /feed/ (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0x10bcb43d0>, 'Connection to blog.uplabs.com timed out. (connect timeout=1)'))\r\n\r\nreal\t0m13.104s\r\nuser\t0m0.149s\r\nsys\t0m0.098s\r\n```\r\n\r\nMy question - it does appear to be timing out, but shouldn't it be timing out much quicker? I'm giving a timeout of 1 but it appears to be taking 13 seconds for the entire script to run. It appears the original host is 301ing me to a weird port number but I think the timeout behavior should continue to apply.\r\n\r\nIf I increase timeout to 2 seconds, it takes 24 seconds:\r\n```\r\nreal\t0m24.626s\r\nuser\t0m0.155s\r\nsys\t0m0.099s\r\n```\r\n\r\nand 3 second timeout takes 36 seconds. So it appears to be compounding?\r\n```\r\nreal\t0m37.152s\r\nuser\t0m0.156s\r\nsys\t0m0.108s\r\n```\r\n\r\nIs there an additional setting I am missing or case I should deal with? Using requests 2.11\r\n\r\n```\r\n>>> import requests\r\n>>> requests.__version__\r\n'2.11.1'\r\n```"}}
{"actor":{"display_login":"haydenth"}}