<p dir="auto">Request header keys are being encoded and then checked for later. In python 3 this is causing issues.</p>
<p dir="auto">In an example use case, if <code class="notranslate">Content-Type</code> is explicitly set, when making a post request, you end up getting both the user-set type and the default type, eg: <code class="notranslate">application/x-www-form-urlencoded</code>.</p>
<p dir="auto"><a href="https://github.com/kennethreitz/requests/blob/master/requests/models.py#L364">https://github.com/kennethreitz/requests/blob/master/requests/models.py#L364</a></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="headers = dict((name.encode('ascii'), value) for name, value in headers.items())"><pre class="notranslate"><span class="pl-s1">headers</span> <span class="pl-c1">=</span> <span class="pl-en">dict</span>((<span class="pl-s1">name</span>.<span class="pl-en">encode</span>(<span class="pl-s">'ascii'</span>), <span class="pl-s1">value</span>) <span class="pl-k">for</span> <span class="pl-s1">name</span>, <span class="pl-s1">value</span> <span class="pl-c1">in</span> <span class="pl-s1">headers</span>.<span class="pl-en">items</span>())</pre></div>
<p dir="auto"><a href="https://github.com/kennethreitz/requests/blob/master/requests/models.py#L417">https://github.com/kennethreitz/requests/blob/master/requests/models.py#L417</a></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# Add content-type if it wasn't explicitly provided.
if (content_type) and (not 'content-type' in self.headers):
            self.headers['Content-Type'] = content_type"><pre class="notranslate"><span class="pl-c"># Add content-type if it wasn't explicitly provided.</span>
<span class="pl-k">if</span> (<span class="pl-s1">content_type</span>) <span class="pl-c1">and</span> (<span class="pl-c1">not</span> <span class="pl-s">'content-type'</span> <span class="pl-c1">in</span> <span class="pl-s1">self</span>.<span class="pl-s1">headers</span>):
            <span class="pl-s1">self</span>.<span class="pl-s1">headers</span>[<span class="pl-s">'Content-Type'</span>] <span class="pl-c1">=</span> <span class="pl-s1">content_type</span></pre></div>
<h2 dir="auto">Summary</h2>
<p dir="auto">Started getting SSLError when invoking API using requests module.<br>
SSLError: HTTPSConnectionPool(host=', port=443): Max retries exceeded with url: /oauth/token (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),))</p>
<p dir="auto">Just to add that this is on RHEL</p>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">ssl.OPENSSL_VERSION<br>
'OpenSSL 1.0.1e-fips 11 Feb 2013'</p>
</blockquote>
</blockquote>
</blockquote>
<p dir="auto">The system openssl is<br>
Version     : 1.0.1e,<br>
Release     : 58.el6_10</p>
<p dir="auto">python was built using source.</p>
<h2 dir="auto">Expected Result</h2>
<p dir="auto">Was not expecting an SSLError. This is not a problem with the source website as the same call works fine using postman. Could this have anything to do with letsencryt root certificate expiration?</p>
<h2 dir="auto">Actual Result</h2>
<p dir="auto">SSLError: HTTPSConnectionPool(host=', port=443): Max retries exceeded with url: /oauth/token (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),))</p>
<h2 dir="auto">Reproduction Steps</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Invoke API using python requests and without verify=False
"><pre class="notranslate"><code class="notranslate">Invoke API using python requests and without verify=False

</code></pre></div>
<h2 dir="auto">System Information</h2>
<p dir="auto">Just to add that this is on RHEL</p>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">ssl.OPENSSL_VERSION<br>
'OpenSSL 1.0.1e-fips 11 Feb 2013'</p>
</blockquote>
</blockquote>
</blockquote>
<p dir="auto">The system openssl is<br>
Version     : 1.0.1e,<br>
Release     : 58.el6_10</p>
<p dir="auto">python was built using source.</p>
<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;4.0.0&quot;
  },
  &quot;charset_normalizer&quot;: {
    &quot;version&quot;: null
  },
  &quot;cryptography&quot;: {
    &quot;version&quot;: &quot;&quot;
  },
  &quot;idna&quot;: {
    &quot;version&quot;: &quot;2.10&quot;
  },
  &quot;implementation&quot;: {
    &quot;name&quot;: &quot;CPython&quot;,
    &quot;version&quot;: &quot;2.7.9&quot;
  },
  &quot;platform&quot;: {
    &quot;release&quot;: &quot;2.6.32-754.9.1.el6.x86_64&quot;,
    &quot;system&quot;: &quot;Linux&quot;
  },
  &quot;pyOpenSSL&quot;: {
    &quot;openssl_version&quot;: &quot;&quot;,
    &quot;version&quot;: null
  },
  &quot;requests&quot;: {
    &quot;version&quot;: &quot;2.26.0&quot;
  },
  &quot;system_ssl&quot;: {
    &quot;version&quot;: &quot;1000105f&quot;
  },
  &quot;urllib3&quot;: {
    &quot;version&quot;: &quot;1.26.6&quot;
  },
  &quot;using_charset_normalizer&quot;: false,
  &quot;using_pyopenssl&quot;: false
}
"><pre class="notranslate"><code class="notranslate">{
  "chardet": {
    "version": "4.0.0"
  },
  "charset_normalizer": {
    "version": null
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.10"
  },
  "implementation": {
    "name": "CPython",
    "version": "2.7.9"
  },
  "platform": {
    "release": "2.6.32-754.9.1.el6.x86_64",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.26.0"
  },
  "system_ssl": {
    "version": "1000105f"
  },
  "urllib3": {
    "version": "1.26.6"
  },
  "using_charset_normalizer": false,
  "using_pyopenssl": false
}

</code></pre></div>
<p dir="auto">This command is only available on Requests v2.16.4 and greater. Otherwise,<br>
please provide some basic information about your system (Python version,<br>
operating system, &amp;c).</p>