truststore icon indicating copy to clipboard operation
truststore copied to clipboard

`inject_into_ssl()` not working in virtual environment (Windows 10)

Open mydoghasfleas opened this issue 1 year ago • 3 comments

I am using truststore.inject_into_ssl() for a little app/script.

When I run it in a virtual environment (where I installed truststore separately) it gives me an error (see below).

When I run the same thing directly with my Python interpreter installed in Windows (10), it works.

Is there something I am missing in my virtual environment setup?

  File "C:\Users\user1\Development\python\myapp\Lib\site-packages\requests\sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\Development\python\myapp\Lib\site-packages\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\Development\python\myapp\Lib\site-packages\requests\sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\Development\python\myapp\Lib\site-packages\requests\adapters.py", line 667, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "C:\Users\user1\Development\python\myapp\Lib\site-packages\urllib3\connectionpool.py", line 789, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\Development\python\myapp\Lib\site-packages\urllib3\connectionpool.py", line 466, in _make_request
    self._validate_conn(conn)
  File "C:\Users\user1\Development\python\myapp\Lib\site-packages\urllib3\connectionpool.py", line 1095, in _validate_conn
    conn.connect()
  File "C:\Users\user1\Development\python\myapp\Lib\site-packages\urllib3\connection.py", line 652, in connect
    sock_and_verified = _ssl_wrap_socket_and_match_hostname(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\Development\python\myapp\Lib\site-packages\urllib3\connection.py", line 767, in _ssl_wrap_socket_and_match_hostname
    context.verify_mode = resolve_cert_reqs(cert_reqs)
    ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\AppData\Local\Programs\Python\Python311\Lib\ssl.py", line 742, in verify_mode
    super(SSLContext, SSLContext).verify_mode.__set__(self, value)
  File "C:\Users\user1\AppData\Local\Programs\Python\Python311\Lib\ssl.py", line 742, in verify_mode
    super(SSLContext, SSLContext).verify_mode.__set__(self, value)
  File "C:\Users\user1\AppData\Local\Programs\Python\Python311\Lib\ssl.py", line 742, in verify_mode
    super(SSLContext, SSLContext).verify_mode.__set__(self, value)
  [Previous line repeated 491 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object

The following is what pip list reports in my virtual environment:

Package            Version
------------------ ---------
certifi            2024.8.30
charset-normalizer 3.3.2
idna               3.8
numpy              2.1.1
pillow             10.4.0
pip                22.3.1
requests           2.32.3
setuptools         65.5.0
six                1.16.0
truststore         0.9.2
urllib3            2.2.2
wxPython           4.2.1

mydoghasfleas avatar Sep 05 '24 08:09 mydoghasfleas

By the way, I should add: I am working behind a corporate firewall, if that makes any difference.

mydoghasfleas avatar Sep 05 '24 09:09 mydoghasfleas

This might be the same issue that is discussed in https://github.com/sethmlarson/truststore/issues/143

davisagli avatar Sep 05 '24 18:09 davisagli

@davisagli Thank you, that issue pointed me in the right direction.

Comparing the versions of the requests library in my global and pyenv installations, I saw that globally I had 2.28.2, while in the virtual environment I had 2.32.3.

Downgrading to 2.28.2 in the virtual environment did indeed solve the problem. (And I also had this on Linux/WSL, by the way).

Can one conclude from that, that the problem is with requests, or could it be a conjunctive problem between the libraries?

mydoghasfleas avatar Sep 06 '24 05:09 mydoghasfleas

Fixed in https://github.com/sethmlarson/truststore/pull/164

sethmlarson avatar Jan 13 '25 19:01 sethmlarson