<p dir="auto">Summary.<br>
If a http page redirects via 301 to a non-http location, eg a magnet link, requests raises exception and the redirect link is not available except in the error text</p>
<h2 dir="auto">Expected Result</h2>
<p dir="auto">Would be better if it returned status_code=301 and content=redirect link</p>
<h2 dir="auto">Actual Result</h2>
<p dir="auto">exception No connection adapters were found for 'magnet:?xt=urn:btih...</p>
<p dir="auto">I'm currently mocking an API that is consumed by an Android application.<br>
One of the API responses contains a redirect to a custom URL schema <code class="notranslate">app://</code> in the <code class="notranslate">Location</code> header</p>
<p dir="auto">Since I am not interested in my mocked API client in following the redirect (which would raise an InvalidSchema exception anyway), I have set <code class="notranslate">allow_redirects = False</code> on my session object. Although the redirect is not fired, it is still being resolved, causing an exception due to the missing url adapter.</p>
<h2 dir="auto">Expected Result</h2>
<p dir="auto">Since I'm not interested in the redirects being followed, it would make sense to not resolve the redirected request in the first place.</p>
<h2 dir="auto">How to reproduce</h2>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import requests

S = requests.session()
S.allow_redirects = False
destination = https://somesite.example # URL with a redirect to a non-standard protocol
S.get(url=destination)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">requests</span>

<span class="pl-v">S</span> <span class="pl-c1">=</span> <span class="pl-s1">requests</span>.<span class="pl-en">session</span>()
<span class="pl-v">S</span>.<span class="pl-s1">allow_redirects</span> <span class="pl-c1">=</span> <span class="pl-c1">False</span>
<span class="pl-s1">destination</span> <span class="pl-c1">=</span> <span class="pl-s1">https</span>:<span class="pl-c1">//</span><span class="pl-s1">somesite</span>.<span class="pl-s1">example</span> <span class="pl-c"># URL with a redirect to a non-standard protocol</span>
<span class="pl-v">S</span>.<span class="pl-en">get</span>(<span class="pl-s1">url</span><span class="pl-c1">=</span><span class="pl-s1">destination</span>)</pre></div>
<p dir="auto">Response headers (example):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="HTTP/1.1 302 Found
Server: Apache-Coyote
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
Location: app://api-test.somesite.example?q=example
Content-Language: en
Content-Length: 0
Date: Tue, 31 Oct 2017 12:39:17 GMT
Connection: close"><pre class="notranslate"><code class="notranslate">HTTP/1.1 302 Found
Server: Apache-Coyote
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
Location: app://api-test.somesite.example?q=example
Content-Language: en
Content-Length: 0
Date: Tue, 31 Oct 2017 12:39:17 GMT
Connection: close
</code></pre></div>
<p dir="auto">Exception thrown by code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;example.py&quot;, line 6, in &lt;module&gt;
    S.get(url=destination)
in get
    return self.request('GET', url, **kwargs)
  File ~/.local/lib/python2.7/site-packages/requests/sessions.py&quot;, line 518, in request
    resp = self.send(prep, **send_kwargs)
  File &quot;~/.local/lib/python2.7/site-packages/requests/sessions.py&quot;, line 661, in send
    history = [resp for resp in gen] if allow_redirects else []
  File &quot;~/.local/lib/python2.7/site-packages/requests/sessions.py&quot;, line 214, in resolve_redirects
    **adapter_kwargs
  File &quot;~/.local/lib/python2.7/site-packages/requests/sessions.py&quot;, line 633, in send
    adapter = self.get_adapter(url=request.url)
  File &quot;~/.local/lib/python2.7/site-packages/requests/sessions.py&quot;, line 717, in get_adapter
    raise InvalidSchema(&quot;No connection adapters were found for '%s'&quot; % url)
requests.exceptions.InvalidSchema: No connection adapters were found for 'app://api-test.somesite.com?q=example'
"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "example.py", line 6, in &lt;module&gt;
    S.get(url=destination)
in get
    return self.request('GET', url, **kwargs)
  File ~/.local/lib/python2.7/site-packages/requests/sessions.py", line 518, in request
    resp = self.send(prep, **send_kwargs)
  File "~/.local/lib/python2.7/site-packages/requests/sessions.py", line 661, in send
    history = [resp for resp in gen] if allow_redirects else []
  File "~/.local/lib/python2.7/site-packages/requests/sessions.py", line 214, in resolve_redirects
    **adapter_kwargs
  File "~/.local/lib/python2.7/site-packages/requests/sessions.py", line 633, in send
    adapter = self.get_adapter(url=request.url)
  File "~/.local/lib/python2.7/site-packages/requests/sessions.py", line 717, in get_adapter
    raise InvalidSchema("No connection adapters were found for '%s'" % url)
requests.exceptions.InvalidSchema: No connection adapters were found for 'app://api-test.somesite.com?q=example'

</code></pre></div>
<h2 dir="auto">Actual Result</h2>
<p dir="auto">InvalidSchema exception</p>