python HTTPSConnectionPool(host ='oauth2.googleapis.com',port=443):URL:/token超过了最大重试次数

tpgth1q7  于 6个月前  发布在  Python
关注(0)|答案(1)|浏览(84)

请帮我弄清楚。代码工作到上周五没有问题。今天经过几次启动,我一直得到错误:
google.API_core.exceptions.RetryError:Deadline of 600.0s exceeded while calling target function,last exception:HTTPSConnectionPool(host ='oauth2.googleapis.com',port=443):Max retries exceeded with url:/token(Caused by SSLError(SSLCertVerificationError(1,'[SSL:CERTIFICATE_VERIFY_FAILITY] certificate verify failed:unable to get local issuer certificate(_ssl.c:1007')))
我既不能下载也不能发送数据到Big Query。

import pandas as pd
    from dotenv import load_dotenv
    from google.cloud import bigquery
    load_dotenv('.env')
    
    
    def create_bq_conn():
        CREDS_BIG_QUERY = r'C:\Users\path_to_file\some_creds.json'
        bclient = bigquery.Client.from_service_account_json(json_credentials_path=CREDS_BIG_QUERY)
        return bclient
    
    def result_df():
        query_job = create_bq_conn().query('SELECT * FROM `table`') 
        bqdf = query_job.to_dataframe()
        return bqdf
    
    result_df()

字符串

zyfwsgd6

zyfwsgd61#

解决此SSL错误的许多解决方法之一是使用pip install certifipip install --upgrade certifi(如果您已经安装了它)。
您可以使用以下语法确定证书的路径:

import certifi
certifi.where()

字符串
将生成路径文件:

'/user/local/lib/python3.7/site-packages/certifi/cacert.pem'


现在,你可以传递路径来验证:

r = requests.get('url', verify='/user/local/lib/python3.7/site-packages/certifi/cacert.pem')

相关问题