我在使用 gspread 和 oauth2 时遇到问题。我想在电子表格谷歌中写一些信息。
import json
import gspread
from oauth2client.client import SignedJwtAssertionCredentials
json_key = json.load(open('Test-***********.json'))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], bytes(json_key['private_key'], 'utf-8'), scope)
gc = gspread.authorize(credentials)
wks = gc.open("Test").sheet1
当我启动这个程序时,我有错误:
Traceback (most recent call last):
File "write.py", line 10, in <module>
gc = gspread.authorize(credentials)
File "write.py", line 335, in authorize
client.login()
File "write.py", line 98, in login
self.auth.refresh(http)
File "\oauth2client\client.py", line 598, in refresh
self._refresh(http.request)
File "\oauth2client\client.py", line 769, in _refresh
self._do_refresh_request(http_request)
File "\oauth2client\client.py", line 795, in _do_refresh_request
body = self._generate_refresh_request_body()
File "\oauth2client\client.py", line 1425, in _generate_refresh_request_body
assertion = self._generate_assertion()
File "\oauth2client\client.py", line 1554, in _generate_assertion
private_key, self.private_key_password), payload)
File "\oauth2client\crypt.py", line 166, in from_string
from OpenSSL import crypto
File "\OpenSSL\__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "\OpenSSL\rand.py", line 11, in <module>
from OpenSSL._util import (
File "\OpenSSL\_util.py", line 6, in <module>
from cryptography.hazmat.bindings.openssl.binding import Binding
ImportError: No module named 'cryptography'
如何解决?我使用 python 3.4 32 位。