Запросы и потоки Python - AttributeError: объект "X509" не имеет атрибута "_x509"

У запросов Python возникают проблемы:

rs = requests.get(STREAM_URL, stream=True,headers=headers)

Process Process-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "oanda_streaming_pairs_server.py", line 287, in multistreamer
    rs = requests.get(STREAM_URL, stream=True,headers=headers)
  File "/usr/local/lib/python2.7/dist-packages/requests-2.12.0-py2.7.egg/requests/api.py", line 70, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests-2.12.0-py2.7.egg/requests/api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests-2.12.0-py2.7.egg/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests-2.12.0-py2.7.egg/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests-2.12.0-py2.7.egg/requests/adapters.py", line 423, in send
    timeout=timeout
  File "/usr/local/lib/python2.7/dist-packages/requests-2.12.0-py2.7.egg/requests/packages/urllib3/connectionpool.py", line 594, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python2.7/dist-packages/requests-2.12.0-py2.7.egg/requests/packages/urllib3/connectionpool.py", line 350, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python2.7/dist-packages/requests-2.12.0-py2.7.egg/requests/packages/urllib3/connectionpool.py", line 835, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python2.7/dist-packages/requests-2.12.0-py2.7.egg/requests/packages/urllib3/connection.py", line 330, in connect
    cert = self.sock.getpeercert()
  File "/usr/local/lib/python2.7/dist-packages/requests-2.12.0-py2.7.egg/requests/packages/urllib3/contrib/pyopenssl.py", line 324, in getpeercert
    'subjectAltName': get_subj_alt_name(x509)
  File "/usr/local/lib/python2.7/dist-packages/requests-2.12.0-py2.7.egg/requests/packages/urllib3/contrib/pyopenssl.py", line 166, in get_subj_alt_name
    cert = _Certificate(openssl_backend, peer_cert._x509)
AttributeError: 'X509' object has no attribute '_x509'

Ответ 1

В моем случае оказалось, что версия pyOpenSSL была слишком старой. Мой Ubuntu 14.4 выполнял версию 0.13 pyOpenSSL. Я получил сообщение об ошибке с библиотекой python elasticsearch.

Мне пришлось обновить pyOpenSSL, выполнив:

sudo pip install -U pyOpenSSL

Вы можете проверить версию pyOpenSSL с помощью

python -c 'import OpenSSL; print(OpenSSL.__version__)'

Ответ 2

Вам нужна версия PyOpenSSL как минимум 0.14.

Ответ 3

Это сработало для меня, от: https://libraries.io/pypi/azure-cli-cloud

Если вы запустили объект AttributeError: "X509" не имеет ошибки атрибута "_x509", понизите версию библиотеки запросов с 2.12.1 до 2.11.1. Use pip install requests==2.11.1.