Python请求和流 - AttributeError:'X509'对象没有属性'_x509'

时间:2016-11-16 09:27:00

标签: python python-requests

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'

4 个答案:

答案 0 :(得分:10)

就我而言,事实证明pyOpenSSL的版本太旧了。我的Ubuntu 14.4运行了pyOpenSSL的0.13版本。我收到了弹性搜索python库报告的错误。

我必须通过运行:

来更新pyOpenSSL
sudo pip install -U pyOpenSSL

您可以使用以下命令检查pyOpenSSL版本:

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

答案 1 :(得分:4)

这对我有用,来自:https://libraries.io/pypi/azure-cli-cloud

如果遇到AttributeError:'X509'对象没有属性'_x509'错误,请将您的请求库版本从2.12.1降级到2.11.1。 Use pip install requests==2.11.1.

答案 2 :(得分:2)

你需要PyOpenSSL版本至少0.14。

答案 3 :(得分:0)

https://github.com/kennethreitz/requests/issues/3701 这可能是新版本的错误。