Python AttributeError: 'module' object has

2019-01-16 22:56发布

A Python script of mine is failing with:

Traceback (most recent call last):
  File "./inspect_sheet.py", line 21, in <module>
    main()
  File "./inspect_sheet.py", line 12, in main
    workbook_name=workbook_name,
  File "./google_sheets.py", line 56, in __init__
    self.login()
  File "./google_sheets.py", line 46, in login
    self.client = gspread.authorize(credentials)
  File "/usr/local/lib/python2.7/site-packages/gspread/client.py", line 335, in authorize
    client.login()
  File "/usr/local/lib/python2.7/site-packages/gspread/client.py", line 98, in login
    self.auth.refresh(http)
  File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 598, in refresh
    self._refresh(http.request)
  File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 769, in _refresh
    self._do_refresh_request(http_request)
  File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 795, in _do_refresh_request
    body = self._generate_refresh_request_body()
  File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 1425, in _generate_refresh_request_body
    assertion = self._generate_assertion()
  File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 1554, in _generate_assertion
    private_key, self.private_key_password), payload)
  File "/usr/local/lib/python2.7/site-packages/oauth2client/crypt.py", line 162, in from_string
    from OpenSSL import crypto
  File "/usr/local/lib/python2.7/site-packages/OpenSSL/__init__.py", line 8, in <module>
    from OpenSSL import rand, crypto, SSL
  File "/usr/local/lib/python2.7/site-packages/OpenSSL/SSL.py", line 118, in <module>
    SSL_ST_INIT = _lib.SSL_ST_INIT
AttributeError: 'module' object has no attribute 'SSL_ST_INIT'

16条回答
beautiful°
2楼-- · 2019-01-16 23:45

I saw the AttributeError: 'module' object has no attribute 'SSL_ST_INIT' error too.

Doing

sudo pip install pyOpenSSL==16.2.0

resolved it for me.

查看更多
女痞
3楼-- · 2019-01-16 23:46

I did this which helped:

$ easy_install -U pip $ easy_install -U pyOpenSSL

查看更多
一夜七次
4楼-- · 2019-01-16 23:50

I had a similar error:

    from OpenSSL import rand, crypto, SSL
  File "/usr/local/lib/python3.5/dist-packages/OpenSSL/SSL.py", line 112, in <module>
    SSL_ST_INIT = _lib.SSL_ST_INIT
AttributeError: module 'lib' has no attribute 'SSL_ST_INIT'

and none of the other answers could fix it, because pip could not install anything. Instead, what I did was this from the terminal first:

sudo rm -r /usr/local/lib/python3.5/dist-packages/OpenSSL

Then reinstalled pyopenssl with pip:

sudo pip install pyopenssl

and everything was gravy.

查看更多
混吃等死
5楼-- · 2019-01-16 23:50

My problem was caused by the version of Python openssl that was in /usr/lib/python2.7/dist-packages/.

dpkg -l | grep openssl showed:

ii  python-openssl                                0.15.1-2build1                               all          Python 2 wrapper around the OpenSSL library

I removed it using sudo apt-get remove python-openssl. I then ran the following to install the distribution version of pip.

curl -o ./get-pip.py https://bootstrap.pypa.io/get-pip.py
sudo python2 ./get-pip.py

pip --version now displays:

pip 18.0 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

I was then able to perform the necessary pip install I was trying to complete.

查看更多
登录 后发表回答