Docker客户端连接中的Python - tlsv1警报协议版本错误 [英] Python - tlsv1 alert protocol version error in Docker client connection

查看:1283
本文介绍了Docker客户端连接中的Python - tlsv1警报协议版本错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Docker-py dockerpty ,以便 exec 使用 Docker的命令 Python API。

I'm using Docker-py and dockerpty in order to exec commands using the Docker Python API.

代码很简单:

container = client.inspect_container(containerId)[0]
dockerpty.exec_command(client, container, command)

我想执行命令,例如 echo'hello'它工作正常。但是,尽管我能够获得终端,但是导致以下错误:

When I want to execute commands such as echo 'hello' it works fine. However, commands like /bin/bash, even though I'm able to get the terminal, it is causing the following error:

ubuntu:test$ python main.py exec [containerid] /bin/bash
root@so1:/opt/apache# Traceback (most recent call last):
  File "__main__.py", line 216, in <module>
    main()
  File "__main__.py", line 201, in main
    ec.execute()
    dockerpty.exec_command(client, container, command)
  File "/usr/local/lib/python2.7/site-packages/dockerpty/__init__.py", line 44, in exec_command
    PseudoTerminal(client, operation).start()
  File "/usr/local/lib/python2.7/site-packages/dockerpty/pty.py", line 334, in start
    self._hijack_tty(pumps)
  File "/usr/local/lib/python2.7/site-packages/dockerpty/pty.py", line 373, in _hijack_tty
    pump.flush()
  File "/usr/local/lib/python2.7/site-packages/dockerpty/io.py", line 367, in flush
    read = self.from_stream.read(n)
  File "/usr/local/lib/python2.7/site-packages/dockerpty/io.py", line 120, in read
    return self.fd.recv(n)
  File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 194, in recv
    data = self.connection.recv(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/OpenSSL/SSL.py", line 1302, in recv
    self._raise_ssl_error(self._ssl, result)
  File "/usr/local/lib/python2.7/site-packages/OpenSSL/SSL.py", line 1172, in _raise_ssl_error
    _raise_current_error()
  File "/usr/local/lib/python2.7/site-packages/OpenSSL/_util.py", line 48, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'ssl3_read_bytes', 'tlsv1 alert protocol version')]

当我创建客户端时,我指定 tls_config 使用 tlsv1.2

When I create the client, I specify the tls_config to use tlsv1.2:

    tls_config = docker.tls.TLSConfig(
        client_cert=(cert, key),
        ssl_version=ssl.PROTOCOL_TLSv1_2,
    )
    client = docker.Client(base_url=url, timeout=timeout,
                           tls=tls_config, user_agent=user_agent)

为什么我得到这个'tlsv1警报协议版本错误,如何解决?

Why am I getting this 'tlsv1 alert protocol version' error, and how can I fix this?

推荐答案

在一些较旧版本的Python中, ssl.PROTOCOL_TLSv1_2 不可用。您可以通过尝试从容器内的Python控制台导入它来轻松检查:

In some older versions of Python, ssl.PROTOCOL_TLSv1_2 isn't available. You can easily check by attempting to import it from the Python console inside the container:

root@57c6d8b01861:/# python
Python 2.7.8 (default, Nov 26 2014, 22:28:51) 
>>> import ssl
>>> ssl.PROTOCOL_TLSv1_2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'PROTOCOL_TLSv1_2'
>>> ssl.PROTOCOL_TLSv1
3

如果是这种情况,请尝试在Docker图像中更新Python到> = 2.7.9

If this is the case, try updating Python in your docker image to >=2.7.9.

还要确保 openssl 版本是> = 1.0.1

Also ensure that the openssl version is >=1.0.1.

这篇关于Docker客户端连接中的Python - tlsv1警报协议版本错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆