Skip to content

windowsservercore: urllib SSL errors #359

Description

@lazka

I can't get SSL to work in the container, any ideas welcome:

docker run -it python:3.7.1-windowsservercore
>>> import urllib.request; urllib.request.urlopen("https://letsencrypt.org/")
Traceback (most recent call last):
  File "C:\Python\lib\urllib\request.py", line 1317, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "C:\Python\lib\http\client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Python\lib\http\client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Python\lib\http\client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Python\lib\http\client.py", line 1016, in _send_output
    self.send(msg)
  File "C:\Python\lib\http\client.py", line 956, in send
    self.connect()
  File "C:\Python\lib\http\client.py", line 1392, in connect
    server_hostname=server_hostname)
  File "C:\Python\lib\ssl.py", line 412, in wrap_socket
    session=session
  File "C:\Python\lib\ssl.py", line 853, in _create
    self.do_handshake()
  File "C:\Python\lib\ssl.py", line 1117, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1051)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Python\lib\urllib\request.py", line 525, in open
    response = self._open(req, data)
  File "C:\Python\lib\urllib\request.py", line 543, in _open
    '_open', req)
  File "C:\Python\lib\urllib\request.py", line 503, in _call_chain
    result = func(*args)
  File "C:\Python\lib\urllib\request.py", line 1360, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "C:\Python\lib\urllib\request.py", line 1319, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1051)>
>>>

Activity

  1. tianon commented on Dec 31, 2018

    @tianon
    Member

    I've verified that this is indeed an issue, but I've no idea where to turn to figure out what's going on. 😞

  2. lazka commented on Dec 31, 2018

    @lazka
    Author

    Thanks for checking. Yeah, information about this seems sparse.

    One workaround (for users) would be to pip install certifi and set the SSL_CERT_FILE env var to the contained cacert.pem

  3. tianon commented on Jan 3, 2019

    @tianon
    Member

    As another data point, whether the error drops seems to depend on the site you're trying to hit; for example, doing urllib.request.urlopen("https://bootstrap.pypa.io/get-pip.py"), I do not get an error. 🤷‍♂️

  4. mika-fischer commented on Feb 27, 2019

    @mika-fischer

    I have the same issue, maybe this whould be forwarded to the Python people?

  5. tianon commented on Feb 27, 2019

    @tianon
    Member
  6. mika-fischer commented on Feb 27, 2019

    @mika-fischer

    Well I have the issue also with mcr.microsoft.com/windows which is not so minimal anymore. Not sure what else to test.

    I'll have a look and file a bug on the Python tracker.

  7. mika-fischer commented on Feb 27, 2019

    @mika-fischer
  8. mika-fischer commented on Feb 28, 2019

    @mika-fischer

    As a (limited) workaround, maybe this can be added to the images:

    certutil -generateSSTFromWU roots.sst && certutil -addstore -f root roots.sst && del roots.sst

    But this really needs to be fixed in Python...

  9. AILearner17 commented on Apr 18, 2020

    @AILearner17
  10. AILearner17 commented on Apr 18, 2020

    @AILearner17
  11. AILearner17 commented on Apr 18, 2020

    @AILearner17
  12. tianon commented on Apr 20, 2020

    @tianon
  13. tianon commented on Jun 8, 2022

    @tianon
    Member

    Looks like the latest on this is in https://bugs.python.org/issue36011 python/cpython#80192 (and that it's still a problem 😞).

  14. tianon commented on Feb 13, 2025

    @tianon
    Member

    I just tested this fresh, just to be certain, and it's definitely still an issue on the latest builds. 🙈

  15. LaurentGoderre commented on Feb 13, 2025

    @LaurentGoderre
    Member

    ServerCore seems to come with significantly fewer root authority (Only 2 compared to the dozen on my Windows host.

  16. LaurentGoderre commented on Feb 13, 2025

    @LaurentGoderre
    Member

    It seems the certificates are managed either by Windows Update or by Active Directory policy.

    To install them in the container you can run the following Powershell script

    certutil.exe -generateSSTFromWU .\rootcerts.sst
    $sstFile = (Get-ChildItem -Path .\rootcerts.sst)
    $sstFile | Import-Certificate -CertStoreLocation Cert:\LocalMachine\Root
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions