Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

python - Google API : AttributeError: module 'time' has no attribute 'clock'

This is my code :

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

I'm hitting error at drive with error message :

AttributeError: module 'time' has no attribute 'clock'

I'm using Python 3.8. Please help. I can upload error message if needed.

Error log :

    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'
question from:https://stackoverflow.com/questions/66056550/google-api-attributeerror-module-time-has-no-attribute-clock

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Please check this answer AttributeError: module 'time' has no attribute 'clock' in Python 3.8

I think the easiest solution would be to downgrade your python to python 3.7.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...