繁体   English   中英

Google API:AttributeError:模块“时间”没有属性“时钟”

[英]Google API : AttributeError: module 'time' has no attribute 'clock'

这是我的代码:

from oauth2client.service_account import ServiceAccountCredentials
from apiclient import discovery
from httplib2 import Http

key_path = os.environ["GOOGLE_APPLICATION_CREDENTIALS"]

# define scope
SCOPE = ['https://spreadsheets.google.com/feeds',
        'https://www.googleapis.com/auth/drive']

# define store
credentials = ServiceAccountCredentials.from_json_keyfile_name(key_path, SCOPE)

# define API service
http = credentials.authorize(Http())
drive = discovery.build('drive', 'v3', http=http) # ERROR HERE

我在drive上遇到错误并显示错误消息:

AttributeError:模块“时间”没有属性“时钟”

我正在使用 Python 3.8。 请帮忙。 如果需要,我可以上传错误消息。

错误日志:

    File "/Users/mydirectory/Documents/my-project/config.py", line 36, in <module>
    drive = discovery.build('drive', 'v3', http=http)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/googleapiclient/discovery.py", line 270, in build
    content = _retrieve_discovery_doc(
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/googleapiclient/discovery.py", line 376, in _retrieve_discovery_doc
    resp, content = req.execute(num_retries=num_retries)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/googleapiclient/http.py", line 900, in execute
    resp, content = _retry_request(
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/googleapiclient/http.py", line 177, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/oauth2client/transport.py", line 159, in new_request
    credentials._refresh(orig_request_method)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/oauth2client/client.py", line 749, in _refresh
    self._do_refresh_request(http)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/oauth2client/client.py", line 774, in _do_refresh_request
    body = self._generate_refresh_request_body()
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/oauth2client/client.py", line 1484, in _generate_refresh_request_body
    assertion = self._generate_assertion()
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/oauth2client/service_account.py", line 384, in _generate_assertion
    return crypt.make_signed_jwt(self._signer, payload,
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/oauth2client/crypt.py", line 97, in make_signed_jwt
    signature = signer.sign(signing_input)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/oauth2client/_pycrypto_crypt.py", line 99, in sign
    return PKCS1_v1_5.new(self._key).sign(SHA256.new(message))
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/Crypto/Signature/PKCS1_v1_5.py", line 112, in sign
    m = self._key.decrypt(em)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/Crypto/PublicKey/RSA.py", line 174, in decrypt
    return pubkey.pubkey.decrypt(self, ciphertext)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/Crypto/PublicKey/pubkey.py", line 93, in decrypt
    plaintext=self._decrypt(ciphertext)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/Crypto/PublicKey/RSA.py", line 235, in _decrypt
    r = getRandomRange(1, self.key.n-1, randfunc=self._randfunc)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/Crypto/Util/number.py", line 123, in getRandomRange
    value = getRandomInteger(bits, randfunc)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/Crypto/Util/number.py", line 104, in getRandomInteger
    S = randfunc(N>>3)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 202, in read
    return self._singleton.read(bytes)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 178, in read
    return _UserFriendlyRNG.read(self, bytes)
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 129, in read
    self._ec.collect()
  File "/Users/mydirectory/Documents/my-project/venv/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 77, in collect
    t = time.clock()
AttributeError: module 'time' has no attribute 'clock'

请检查这个答案AttributeError: module 'time' has no attribute 'clock' in Python 3.8

我认为最简单的解决方案是将您的 python 降级到 python 3.7。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM