Skip to content

requests: Can't connect to HTTPS URL because the SSL module is not available. #41

Description

@huimzjty

I use this command to install the python3 by portable-python

yum install python3-pip
pip3 install portable-python

yum install -y libffi libffi-devel python3-devel openssl-devel
yum install -y perl-CPAN
cpan IPC::Cmd
cd /opt/
mkdir portable_with_openssl
cd portable_with_openssl/
portable-python build 3.11.7 -m openssl

mkdir /opt/versions
tar -C /opt/versions/  -xf dist/cpython-3.11.7-linux-x86_64.tar.gz
cd /opt/versions/3.11.7
./bin/python3.11 -mpip install requests

And after import the requests, i can request "http://google.com", but when i request "https://google.com", an error has occurred.

Python 3.11.7 (main, Mar 14 2024, 14:21:08) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>import requests
>>> requests.get("http://google.com")
<Response [200]>
>>> requests.get("https://google.com")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/versions/3.11.7/lib/python3.11/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/versions/3.11.7/lib/python3.11/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/versions/3.11.7/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/versions/3.11.7/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/versions/3.11.7/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/opt/versions/3.11.7/lib/python3.11/site-packages/urllib3/connectionpool.py", line 772, in urlopen
    conn = self._get_conn(timeout=pool_timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/versions/3.11.7/lib/python3.11/site-packages/urllib3/connectionpool.py", line 295, in _get_conn
    return conn or self._new_conn()
                   ^^^^^^^^^^^^^^^^
  File "/opt/versions/3.11.7/lib/python3.11/site-packages/urllib3/connectionpool.py", line 1063, in _new_conn
    raise ImportError(
ImportError: Can't connect to HTTPS URL because the SSL module is not available.

Does the requests library only use the SSL module in the system to process HTTPS requests?

Activity

  1. zsimic commented on Mar 14, 2024

    @zsimic
    Contributor

    What does this say?

    /opt/versions/3.11.7/bin/python3 -c 'import _ssl; print(_ssl.OPENSSL_VERSION)'
    

    I am not super familiar with requests off the top of my head, but I think it eventually relies on std lib module _ssl.

  2. huimzjty commented on Mar 15, 2024

    @huimzjty
    Author

    What does this say?

    /opt/versions/3.11.7/bin/python3 -c 'import _ssl; print(_ssl.OPENSSL_VERSION)'
    

    I am not super familiar with requests off the top of my head, but I think it eventually relies on std lib module _ssl.

    The command output:

    [root@VM-12-10-centos 3.11.7]# /opt/versions/3.11.7/bin/python3 -c 'import _ssl; print(_ssl.OPENSSL_VERSION)'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ModuleNotFoundError: No module named '_ssl'
    

    it seem that python compilation does not include OpenSSL support.

  3. zsimic commented on Mar 15, 2024

    @zsimic
    Contributor

    I need to write more docs. It seems that you didn't enable openssl. If you build without config, then run:

    portable-python build 3.11.7 -mopenssl
    

    And do add more, if you need more, on macos for example, I do -mxz,openssl (comma separated list of components to build-in statically).
    Run this for example and inspect the build report (you'll see what will be static/shared, not included etc):

    portable-python build-report 3.11.7 -mxz,openssl
    

    You can also configure this in a file, here's what I use (on linux, portable python in this case):

    linux:
      cpython-modules: libffi zlib xz bzip2 readline sqlite uuid openssl
    
  4. zsimic commented on Mar 15, 2024

    @zsimic
    Contributor

    If you see openssl shown as "shared" when you run portable-python build-report 3.11.7, then it means that the openssl shared lib was not found at runtime when you try this.
    If it shows as "absent", it means your openssl installation was not detected (an -mopenssl will fetch source code of openssl and build it in statically)

  5. huimzjty commented on Apr 25, 2024

    @huimzjty
    Author

    i found the config.log, it show

    configure:23298: gcc -pthread -o conftest  -I/opt/pp/build/deps/include   -L/opt/pp/build/deps/lib  conftest.c -lpthread -ldl  -lutil -lssl -lcrypto >&5
      38280 /usr/bin/ld: cannot find -lssl
      38281 /usr/bin/ld: cannot find -lcrypto
    

    And it is because the path is 'build/deps/lib64', and by default, it will search for 'build/deps/lib'.
    So before portable-python build 3.11.7 -m openssl, command export LIBRARY_PATH=/opt/py/build/deps/lib64:$LIBRARY_PATH.
    And then build success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions