{"issue":{"state":"open","pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"milestone":null,"user":{"avatar_url":"https://secure.gravatar.com/avatar/caa0ee22a59ee7a4fc261281940ccb54?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"caa0ee22a59ee7a4fc261281940ccb54","url":"https://api.github.com/users/dmytton","login":"dmytton","id":117833},"assignee":null,"updated_at":"2011-11-17T12:39:13Z","labels":[],"comments":5,"closed_at":null,"url":"https://api.github.com/repos/kennethreitz/requests/issues/209","body":"The location header in a 302 redirect response is not being parsed correctly when it has special characters in it.\r\n\r\n`/Login.aspx?ReturnUrl=%2f` becomes `/Login.aspx%3FReturnUrl%3D/` \r\n\r\nWhen followed, this results in a 404 because it's not correct.\r\n\r\n```python\r\n>>> import requests\r\n>>> r = requests.get('http://affiliatenetwork.ist-apps.com')\r\n>>> r.status_code\r\n404\r\n>>> print r.headers\r\n{'content-length': '1245', 'x-powered-by': 'ASP.NET', 'date': 'Tue, 18 Oct 2011 09:15:08 GMT', 'content-type': 'text/html', 'connection': 'close', 'server': 'Microsoft-IIS/7.0'}\r\n>>> r.url\r\n'http://affiliatenetwork.ist-apps.com/Login.aspx%3FReturnUrl%3D/'\r\n>>> r.history\r\n[<Response [302]>]\r\n>>> r.history[0].headers\r\n{'content-length': '142', 'x-powered-by': 'ASP.NET', 'x-aspnet-version': '4.0.30319', 'server': 'Microsoft-IIS/7.0', 'connection': 'close', 'location': '/Login.aspx?ReturnUrl=%2f', 'cache-control': 'private', 'date': 'Tue, 18 Oct 2011 10:56:08 GMT', 'content-type': 'text/html; charset=utf-8'}\r\n```\r\n\r\ncurl parses this correctly:\r\n\r\n```shell\r\ndavid@Shibuya ~: curl -v http://affiliatenetwork.ist-apps.com\r\n* About to connect() to affiliatenetwork.ist-apps.com port 80 (#0)\r\n*   Trying 94.236.92.60... connected\r\n* Connected to affiliatenetwork.ist-apps.com (94.236.92.60) port 80 (#0)\r\n> GET / HTTP/1.1\r\n> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5\r\n> Host: affiliatenetwork.ist-apps.com\r\n> Accept: */*\r\n> \r\n< HTTP/1.1 302 Found\r\n< Cache-Control: private\r\n< Content-Type: text/html; charset=utf-8\r\n< Location: /Login.aspx?ReturnUrl=%2f\r\n< Server: Microsoft-IIS/7.0\r\n< X-AspNet-Version: 4.0.30319\r\n< X-Powered-By: ASP.NET\r\n< Date: Tue, 18 Oct 2011 11:26:34 GMT\r\n< Content-Length: 142\r\n< \r\n<html><head><title>Object moved</title></head><body>\r\n<h2>Object moved to <a href=\"/Login.aspx?ReturnUrl=%2f\">here</a>.</h2>\r\n</body></html>\r\n* Connection #0 to host affiliatenetwork.ist-apps.com left intact\r\n* Closing connection #0\r\n```\r\n\r\nhttplib also parses this correctly:\r\n\r\n```python\r\n>>> conn = httplib.HTTPConnection('affiliatenetwork.ist-apps.com')\r\n>>> conn.request(\"GET\",\"/\")\r\n>>> res = conn.getresponse()\r\n>>> print res.status\r\n302\r\n>>> print res.reason\r\nFound\r\n>>> print res.getheaders()\r\n[('content-length', '142'), ('x-powered-by', 'ASP.NET'), ('x-aspnet-version', '4.0.30319'), ('server', 'Microsoft-IIS/7.0'), ('location', '/Login.aspx?ReturnUrl=%2f'), ('cache-control', 'private'), ('date', 'Tue, 18 Oct 2011 10:35:20 GMT'), ('content-type', 'text/html; charset=utf-8')]\r\n```\r\n\r\nLooks like the problem is caused by https://github.com/kennethreitz/requests/blob/master/requests/models.py#L237\r\n\r\n```python\r\n>>> url = '/Login.aspx?ReturnUrl=%2f'\r\n>>> o = urlparse.urlparse(url)\r\n>>> print o\r\nParseResult(scheme='', netloc='', path='/Login.aspx', params='', query='ReturnUrl=%2f', fragment='')\r\n>>> import urllib\r\n>>> urllib.quote(urllib.unquote(url))\r\n'/Login.aspx%3FReturnUrl%3D/'\r\n>>> urllib.unquote(url)\r\n'/Login.aspx?ReturnUrl=/'\r\n```","html_url":"https://github.com/kennethreitz/requests/issues/209","title":"Incorrect parsing of HTTP redirect location special characters","number":209,"id":1938497,"created_at":"2011-10-18T11:29:14Z"},"action":"created","comment":{"user":{"avatar_url":"https://secure.gravatar.com/avatar/caa0ee22a59ee7a4fc261281940ccb54?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"caa0ee22a59ee7a4fc261281940ccb54","url":"https://api.github.com/users/dmytton","login":"dmytton","id":117833},"updated_at":"2011-11-17T12:39:13Z","url":"https://api.github.com/repos/kennethreitz/requests/issues/comments/2775525","body":"Patch submitted in https://github.com/kennethreitz/requests/pull/273","id":2775525,"created_at":"2011-11-17T12:39:13Z"}}