From 824d54f13111387df941f7e6f02b8ac064bec04e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81re=CC=81my=20Bethmont?= Date: Fri, 2 Sep 2011 15:06:58 +0200 Subject: [PATCH] Only the path should be encoded (not the query, otherwise it makes a wrong redirection). --- requests/models.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/requests/models.py b/requests/models.py index 2d7fc8fe..4af0597d 100644 --- a/requests/models.py +++ b/requests/models.py @@ -224,8 +224,11 @@ class Request(object): # Facilitate non-RFC2616-compliant 'location' headers # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource') - if not urlparse(url).netloc: - url = urljoin(r.url, urllib.quote(urllib.unquote(url))) + parsed_url = urlparse(url) + if not parsed_url.netloc: + parsed_url = list(parsed_url) + parsed_url[2] = urllib.quote(urllib.unquote(parsed_url[2])) + url = urljoin(r.url, str(urlunparse(parsed_url))) # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4 if r.status_code is codes.see_other: