Problem with 301-redirect

I have a problem with downloading a file, when the server returns the 301 code:

``` python
r = requests.get('http://servag.rupsy.ru/track.php?url=2013-04-11/Haatzumaniak_-_Dark_Sadhu_[2013]/03.%20Haatzumaniak_-_777_Dark%20Sadhu%202013.mp3&arj=Haatzumaniak_-_Dark_Sadhu_[2013].ZIP')
print(r)
```

If you do redirect manually - it works fine:

``` python
r = requests.get('http://servag.rupsy.ru/track.php?url=2013-04-11/Haatzumaniak_-_Dark_Sadhu_[2013]/03.%20Haatzumaniak_-_777_Dark%20Sadhu%202013.mp3&arj=Haatzumaniak_-_Dark_Sadhu_[2013].ZIP', allow_redirects=False)
r = requests.get(r.headers['Location'])
print(r)
```

The problem appears to Python 3.3 and python-requests-1.2.0/python-requests-dev

```
Traceback (most recent call last):
  File "C:\Dropbox\projects\Helpers\ph\.envwin32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 428, in urlopen
    body=body, headers=headers)
  File "C:\Dropbox\projects\Helpers\ph\.envwin32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 290, in _make_request
    httplib_response = conn.getresponse()
  File "c:\Python33\lib\http\client.py", line 1143, in getresponse
    response.begin()
  File "c:\Python33\lib\http\client.py", line 354, in begin
    version, status, reason = self._read_status()
  File "c:\Python33\lib\http\client.py", line 324, in _read_status
    raise BadStatusLine(line)
http.client.BadStatusLine: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Dropbox\projects\Helpers\ph\.envwin32\lib\site-packages\requests\adapters.py", line 283, in send
    timeout=timeout
  File "C:\Dropbox\projects\Helpers\ph\.envwin32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 474, in urlopen
    raise MaxRetryError(self, url, e)
requests.packages.urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='servag.rupsy.ru', port=80): Max retries exceeded with url: /media/2/Haatzumaniak_-_Dark_Sadhu_[2013]/03. Haatzumaniak_-_777_Dark Sadhu 2013.mp3 (Caused by <class 'http.client.BadStatusLine'>: '')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Dropbox/projects/InfoStreams/test.py", line 25, in <module>
    allow_redirects=True)
  File "C:\Dropbox\projects\Helpers\ph\.envwin32\lib\site-packages\requests\api.py", line 55, in get
    return request('get', url, **kwargs)
  File "C:\Dropbox\projects\Helpers\ph\.envwin32\lib\site-packages\requests\api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Dropbox\projects\Helpers\ph\.envwin32\lib\site-packages\requests\sessions.py", line 345, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Dropbox\projects\Helpers\ph\.envwin32\lib\site-packages\requests\sessions.py", line 464, in send
    history = [resp for resp in gen] if allow_redirects else []
  File "C:\Dropbox\projects\Helpers\ph\.envwin32\lib\site-packages\requests\sessions.py", line 464, in <listcomp>
    history = [resp for resp in gen] if allow_redirects else []
  File "C:\Dropbox\projects\Helpers\ph\.envwin32\lib\site-packages\requests\sessions.py", line 154, in resolve_redirects
    allow_redirects=False,
  File "C:\Dropbox\projects\Helpers\ph\.envwin32\lib\site-packages\requests\sessions.py", line 448, in send
    r = adapter.send(request, **kwargs)
  File "C:\Dropbox\projects\Helpers\ph\.envwin32\lib\site-packages\requests\adapters.py", line 318, in send
    raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='servag.rupsy.ru', port=80): Max retries exceeded with url: /media/2/Haatzumaniak_-_Dark_Sadhu_[2013]/03. Haatzumaniak_-_777_Dark Sadhu 2013.mp3 (Caused by <class 'http.client.BadStatusLine'>: '')
```


Uh...can I ask you to uninstall and reinstall Requests? The TypeError that got thrown should have been impossible to hit, because it's inside a Try/Catch block that catches TypeErrors.


Ignore the first trace (I'll delete it), the key of the problem is:

```
File "c:\Python33\lib\http\client.py", line 324, in _read_status
    raise BadStatusLine(line)
```


Ah, ok, got it.

The issue is that the remote server is not following RFC 2616. The Location header should be percent-encoded, and hasn't been. This doesn't matter if you pass the URL through Requests from the top, because it gets percent-encoded by prepare_url.

**EDIT**: To be clear, we should handle this: I'll have a fix ready shortly.


Lucasa, thank you very much - now works fine