google-api-python-client因OAuth2而损坏?

问题描述 投票:0回答:1

我正在尝试使用Python中的Google Api客户端检查bigquery中是否存在某些数据集。 直到最后一次更新我都遇到了这个我不知道如何解决的奇怪错误,它才能一直起作用:

Traceback (most recent call last):
  File "/root/miniconda/lib/python2.7/site-packages/dsUtils/bq_utils.py", line 106, in _get
    resp = bq_service.datasets().get(projectId=self.project_id, datasetId=self.id).execute(num_retries=2)
  File "/root/miniconda/lib/python2.7/site-packages/oauth2client/util.py", line 140, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/root/miniconda/lib/python2.7/site-packages/googleapiclient/http.py", line 755, in execute
    method=str(self.method), body=self.body, headers=self.headers)
  File "/root/miniconda/lib/python2.7/site-packages/googleapiclient/http.py", line 93, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "/root/miniconda/lib/python2.7/site-packages/oauth2client/client.py", line 598, in new_request
    self._refresh(request_orig)
  File "/root/miniconda/lib/python2.7/site-packages/oauth2client/client.py", line 864, in _refresh
    self._do_refresh_request(http_request)
  File "/root/miniconda/lib/python2.7/site-packages/oauth2client/client.py", line 891, in _do_refresh_request
    body = self._generate_refresh_request_body()
  File "/root/miniconda/lib/python2.7/site-packages/oauth2client/client.py", line 1597, in _generate_refresh_req
uest_body
    assertion = self._generate_assertion()
  File "/root/miniconda/lib/python2.7/site-packages/oauth2client/service_account.py", line 263, in _generate_ass
ertion
    key_id=self._private_key_id)
  File "/root/miniconda/lib/python2.7/site-packages/oauth2client/crypt.py", line 97, in make_signed_jwt
    signature = signer.sign(signing_input)
  File "/root/miniconda/lib/python2.7/site-packages/oauth2client/_pycrypto_crypt.py", line 101, in sign
    return PKCS1_v1_5.new(self._key).sign(SHA256.new(message))
  File "/root/miniconda/lib/python2.7/site-packages/Crypto/Signature/PKCS1_v1_5.py", line 112, in sign
    m = self._key.decrypt(em)
  File "/root/miniconda/lib/python2.7/site-packages/Crypto/PublicKey/RSA.py", line 174, in decrypt
    return pubkey.pubkey.decrypt(self, ciphertext)
  File "/root/miniconda/lib/python2.7/site-packages/Crypto/PublicKey/pubkey.py", line 93, in decrypt
    plaintext=self._decrypt(ciphertext)
  File "/root/miniconda/lib/python2.7/site-packages/Crypto/PublicKey/RSA.py", line 235, in _decrypt
    r = getRandomRange(1, self.key.n-1, randfunc=self._randfunc)
  File "/root/miniconda/lib/python2.7/site-packages/Crypto/Util/number.py", line 123, in getRandomRange
    value = getRandomInteger(bits, randfunc)
  File "/root/miniconda/lib/python2.7/site-packages/Crypto/Util/number.py", line 104, in getRandomInteger
    S = randfunc(N>>3)
  File "/root/miniconda/lib/python2.7/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 202, in read
    return self._singleton.read(bytes)
  File "/root/miniconda/lib/python2.7/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 178, in read
    return _UserFriendlyRNG.read(self, bytes)
  File "/root/miniconda/lib/python2.7/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 137, in read
    self._check_pid()
  File "/root/miniconda/lib/python2.7/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 153, in _check_pid
    raise AssertionError("PID check failed. RNG must be re-initialized after fork(). Hint: Try Random.atfork()")
AssertionError: PID check failed. RNG must be re-initialized after fork(). Hint: Try Random.atfork()

有人了解发生了什么吗?

请注意,我也遇到了其他错误,例如GCStorage。

另请注意,我使用以下命令加载我的Google凭据:

from oauth2client.client import GoogleCredentials

def get_credentials(credentials_path):  #my json credentials path
    logger.info('Getting credentials...')
    try:
        os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credentials_path
        credentials = GoogleCredentials.get_application_default()
        return credentials
    except Exception as e:
        raise e

因此,如果有人知道使用我的json服务帐户文件来加载我的Google凭据的更好方法,并且可以避免该错误,请告诉我。

python oauth-2.0 google-bigquery google-cloud-storage google-api-client
1个回答
1
投票

看起来该错误出在PyCrypto模块中,该模块似乎由Google的OAuth2实现在后台使用。 如果您的代码在某个时候正在调用os.fork() ,则可能需要随后在父进程和子进程中都调用Crypto.Random.atfork() ,以更新模块的内部状态。

请参阅此处获取PyCrypto文档; 搜索“ atfork”以获取更多信息: https : //github.com/dlitz/pycrypto

此问题和答案也可能是相关的: PyCrypto:AssertionError(“ PID检查失败。必须在fork()之后重新初始化RNG。提示:请尝试Random.atfork()”)

© www.soinside.com 2019 - 2024. All rights reserved.