<p dir="auto">During an upgrade from python 3.7 to 3.9 I face an error similar to the one reported on <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="541767228" data-permission-text="Title is private" data-url="https://github.com/psf/requests/issues/5297" data-hovercard-type="issue" data-hovercard-url="/psf/requests/issues/5297/hovercard" href="https://github.com/psf/requests/issues/5297">#5297</a>.</p>
<p dir="auto">The proxies are defined on the system level (export http_proxy and export https_proxy).</p>
<p dir="auto">It works fine on 3.7.</p>
<h2 dir="auto">Expected Result</h2>
<p dir="auto">Requests respect the proxy</p>
<h2 dir="auto">Actual Result</h2>
<p dir="auto">Proxy causes the request fo fail</p>
<h2 dir="auto">Reproduction Steps</h2>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import requests
headers={}
payload={}
url='https://www.someurl.com'
response = requests.request(&quot;POST&quot;, url, headers=headers, data = payload)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">requests</span>
<span class="pl-s1">headers</span><span class="pl-c1">=</span>{}
<span class="pl-s1">payload</span><span class="pl-c1">=</span>{}
<span class="pl-s1">url</span><span class="pl-c1">=</span><span class="pl-s">'https://www.someurl.com'</span>
<span class="pl-s1">response</span> <span class="pl-c1">=</span> <span class="pl-s1">requests</span>.<span class="pl-en">request</span>(<span class="pl-s">"POST"</span>, <span class="pl-s1">url</span>, <span class="pl-s1">headers</span><span class="pl-c1">=</span><span class="pl-s1">headers</span>, <span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-s1">payload</span>)</pre></div>
<h2 dir="auto">System Information</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ python -m requests.help"><pre class="notranslate"><code class="notranslate">$ python -m requests.help
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
  &quot;chardet&quot;: {
    &quot;version&quot;: &quot;3.0.4&quot;
  },
  &quot;cryptography&quot;: {
    &quot;version&quot;: &quot;&quot;
  },
  &quot;idna&quot;: {
    &quot;version&quot;: &quot;2.8&quot;
  },
  &quot;implementation&quot;: {
    &quot;name&quot;: &quot;CPython&quot;,
    &quot;version&quot;: &quot;3.9.6&quot;
  },
  &quot;platform&quot;: {
    &quot;release&quot;: &quot;20.6.0&quot;,
    &quot;system&quot;: &quot;Darwin&quot;
  },
  &quot;pyOpenSSL&quot;: {
    &quot;openssl_version&quot;: &quot;&quot;,
    &quot;version&quot;: null
  },
  &quot;requests&quot;: {
    &quot;version&quot;: &quot;2.22.0&quot;
  },
  &quot;system_ssl&quot;: {
    &quot;version&quot;: &quot;101010bf&quot;
  },
  &quot;urllib3&quot;: {
    &quot;version&quot;: &quot;1.25.11&quot;
  },
  &quot;using_pyopenssl&quot;: false
}"><pre class="notranslate"><code class="notranslate">{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.8"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.9.6"
  },
  "platform": {
    "release": "20.6.0",
    "system": "Darwin"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.22.0"
  },
  "system_ssl": {
    "version": "101010bf"
  },
  "urllib3": {
    "version": "1.25.11"
  },
  "using_pyopenssl": false
}
</code></pre></div>
<p dir="auto">Traceback</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   response = requests.request(&quot;POST&quot;, url, headers=headers, data = payload)
 File &quot;/usr/local/lib/python3.9/site-packages/requests/api.py&quot;, line 60, in request
   return session.request(method=method, url=url, **kwargs)
 File &quot;/usr/local/lib/python3.9/site-packages/requests/sessions.py&quot;, line 533, in request
   resp = self.send(prep, **send_kwargs)
 File &quot;/usr/local/lib/python3.9/site-packages/requests/sessions.py&quot;, line 646, in send
   r = adapter.send(request, **kwargs)
 File &quot;/usr/local/lib/python3.9/site-packages/requests/adapters.py&quot;, line 412, in send
   conn = self.get_connection(request.url, proxies)
 File &quot;/usr/local/lib/python3.9/site-packages/requests/adapters.py&quot;, line 309, in get_connection
   proxy_manager = self.proxy_manager_for(proxy)
 File &quot;/usr/local/lib/python3.9/site-packages/requests/adapters.py&quot;, line 193, in proxy_manager_for
   manager = self.proxy_manager[proxy] = proxy_from_url(
 File &quot;/usr/local/lib/python3.9/site-packages/urllib3/poolmanager.py&quot;, line 492, in proxy_from_url
   return ProxyManager(proxy_url=url, **kw)
 File &quot;/usr/local/lib/python3.9/site-packages/urllib3/poolmanager.py&quot;, line 429, in __init__
   raise ProxySchemeUnknown(proxy.scheme)"><pre class="notranslate"><code class="notranslate">   response = requests.request("POST", url, headers=headers, data = payload)
 File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 60, in request
   return session.request(method=method, url=url, **kwargs)
 File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 533, in request
   resp = self.send(prep, **send_kwargs)
 File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 646, in send
   r = adapter.send(request, **kwargs)
 File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 412, in send
   conn = self.get_connection(request.url, proxies)
 File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 309, in get_connection
   proxy_manager = self.proxy_manager_for(proxy)
 File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 193, in proxy_manager_for
   manager = self.proxy_manager[proxy] = proxy_from_url(
 File "/usr/local/lib/python3.9/site-packages/urllib3/poolmanager.py", line 492, in proxy_from_url
   return ProxyManager(proxy_url=url, **kw)
 File "/usr/local/lib/python3.9/site-packages/urllib3/poolmanager.py", line 429, in __init__
   raise ProxySchemeUnknown(proxy.scheme)
</code></pre></div>
<p dir="auto">In <a href="https://bugs.python.org/issue27657" rel="nofollow">https://bugs.python.org/issue27657</a> it was decided to reverse an earlier decision about how <code class="notranslate">urllib.parse.urlparse</code> handles URLs that don't specify a scheme (e.g. <code class="notranslate">example.org:80</code>). This behavior change is in Python 3.9.</p>
<p dir="auto">One way this can present to a user is by confusing requests's attempt to add the scheme if it's missing: </p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/psf/requests/blob/1466ad713cf84738cd28f1224a7ab4a19e50e361/requests/utils.py#L904">requests/requests/utils.py</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 904
      in
      <a data-pjax="true" class="commit-tease-sha" href="/psf/requests/commit/1466ad713cf84738cd28f1224a7ab4a19e50e361">1466ad7</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L904" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="904"></td>
          <td id="LC904" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">def</span> <span class="pl-en">prepend_scheme_if_needed</span>(<span class="pl-s1">url</span>, <span class="pl-s1">new_scheme</span>): </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto">With the old behavior, <code class="notranslate">urlparse</code> would return <code class="notranslate">ParseResult(scheme='', netloc='', path='example.org:80', params='', query='', fragment='')</code> and then <code class="notranslate">prepend_scheme_if_needed</code> would happily add the scheme, typically <code class="notranslate">http</code>. With the new behavior, you instead get <code class="notranslate">ParseResult(scheme='example.org', netloc='', path='80', params='', query='', fragment='')</code>, so <code class="notranslate">prepend_scheme_if_needed</code> thinks it has a scheme, and does nothing. Then later, if this is used as a proxy URL, <code class="notranslate">urllib3</code> will complain <a href="https://github.com/urllib3/urllib3/blob/dc25db8e9f03ef2c506431e8a98f77c304ac2941/src/urllib3/poolmanager.py#L534">here</a>, because it has <a href="https://github.com/urllib3/urllib3/blob/dc25db8e9f03ef2c506431e8a98f77c304ac2941/src/urllib3/util/url.py#L348">its own URL parser</a> that is now I think out of sync with the stdlib.</p>
<p dir="auto">(I guess this means you could fix this by making requests use <code class="notranslate">urllib3.util.url.parse_url</code> instead of <code class="notranslate">urllib.parse.urlparse</code>, but that's maybe an antisocial fix)</p>
<h2 dir="auto">Expected Result</h2>
<p dir="auto">If user code has given requests a proxy dict like <code class="notranslate">{'http': 'example.org:80'}</code>, the request is sent through that proxy.</p>
<h2 dir="auto">Actual Result</h2>
<p dir="auto"><code class="notranslate">urllib3</code> raises <code class="notranslate">ProxySchemeUnknown</code></p>
<h2 dir="auto">Reproduction Steps</h2>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import requests
session = requests.Session()
session.proxies = {'https': 'example.org:80'}
session.get('https://www.google.com/')"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">requests</span>
<span class="pl-s1">session</span> <span class="pl-c1">=</span> <span class="pl-s1">requests</span>.<span class="pl-v">Session</span>()
<span class="pl-s1">session</span>.<span class="pl-s1">proxies</span> <span class="pl-c1">=</span> {<span class="pl-s">'https'</span>: <span class="pl-s">'example.org:80'</span>}
<span class="pl-s1">session</span>.<span class="pl-en">get</span>(<span class="pl-s">'https://www.google.com/'</span>)</pre></div>
<h2 dir="auto">System Information</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ python -m requests.help"><pre class="notranslate"><code class="notranslate">$ python -m requests.help
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
  &quot;implementation&quot;: {
    &quot;name&quot;: &quot;CPython&quot;,
    &quot;version&quot;: &quot;3.9.5&quot;
  },
  &quot;platform&quot;: {
    &quot;system&quot;: &quot;Linux&quot;
  },
  &quot;requests&quot;: {
    &quot;version&quot;: &quot;2.22.0&quot;
  },
  &quot;urllib3&quot;: {
    &quot;version&quot;: &quot;1.25.3&quot;
  },
  &quot;using_pyopenssl&quot;: false
}"><pre class="notranslate"><code class="notranslate">{
  "implementation": {
    "name": "CPython",
    "version": "3.9.5"
  },
  "platform": {
    "system": "Linux"
  },
  "requests": {
    "version": "2.22.0"
  },
  "urllib3": {
    "version": "1.25.3"
  },
  "using_pyopenssl": false
}
</code></pre></div>