python-3.x - Python 3.7 和 Dataflow - SSL 证书问题
问题描述
我需要使用 google cloud api 来编写我的 Dataflow 作业。
据我了解,我不能使用,pip install google-cloud-dataflow
因为 Apache Beam 不能在 Python 3 上工作,所以我一直在使用googleapiclient.discovery
. 但是,当我发出build()
命令时,它会引用错误来轰炸:
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)
背景说明:
我坐在企业代理后面,在环境级别设置了 HTTP(S)_PROXY
我还将 CA_BUNDLE 和 REQUESTS_CA_BUNDLE 设置为我的自定义证书
我已经安装了
certifi
,但没有爱我试图运行
/Applications/Python\ 3.6/Install\ Certificates.command
但在我的 virtualenv 中找不到 .command。此外,不希望走这条路,因为它会使我的 Prod 部署成为一场噩梦
这是我的代码:
from oauth2client.client import GoogleCredentials
from googleapiclient.discovery import build
credentials = GoogleCredentials.get_application_default()
dataflow = build('dataflow', 'v1b3', credentials=credentials)
结果:
回溯(最后一次调用):文件“test_dataflow_creds.py”,第 6 行,在 dataflow = build('dataflow', 'v1b3', credentials=credentials) 文件“/Users/user/.pyenv/versions/unit-test -3.7/lib/python3.7/site-packages/googleapiclient/_helpers.py”,第 130 行,在 positional_wrapper 中返回已包装(*args,**kwargs)文件“/Users/user/.pyenv/versions/unit-test -3.7/lib/python3.7/site-packages/googleapiclient/discovery.py”,第 222 行,在 build requested_url、discovery_http、cache_discovery、cache)文件“/Users/user/.pyenv/versions/unit-test-3.7 /lib/python3.7/site-packages/googleapiclient/discovery.py”,第 269 行,在 _retrieve_discovery_doc 中,内容 = http.request(actual_url) 文件“/Users/user/.pyenv/versions/unit-test-3.7 /lib/python3.7/站点包/httplib2/初始化.py”,第 1924 行,在请求缓存键中,文件“/Users/user/.pyenv/versions/unit-test-3.7/lib/python3.7/site-packages/httplib2/init .py ”,第 1595 行,在_request conn、request_uri、方法、正文、标头文件“/Users/user/.pyenv/versions/unit-test-3.7/lib/python3.7/site-packages/httplib2/init .py ”,第 1501 行,在 _conn_request conn.connect() 文件“ /Users/user/.pyenv/versions/unit-test-3.7/lib/python3.7/site-packages/httplib2/init.py”,第 1291 行,在连接 self.sock = self._context.wrap_socket(sock, server_hostname=self.host) 文件“/Users/user/.pyenv/versions/3.7.0/lib/python3.7/ssl .py”,第 412 行,在 wrap_socket session=session 文件中“/Users/user/.pyenv/versions/3.7.0/lib/python3.7/ssl.py”,第 850 行,在 _create self.do_handshake() 文件中“/Users/user/.pyenv/versions/3.7.0/lib/python3.7/ssl.py”,第 1108 行,在 do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败: 无法获取本地颁发者证书 (_ssl.c:1045)
解决方案
tl;dr:通过将所有证书导出到一个公共文件,然后附加到证书文件中指定的路径中的证书文件来使其工作
脚步:
- 在 Firefox > Preferences > View Certificates > Your Certificates 中,导出所有必需的。
- 将上述所有 .crt 文件连接成一个大包。
- 在 bash 中,运行 python -m requests.certs 以获取 python 正在使用的证书文件。
- 将上述步骤 2 中的捆绑证书附加到步骤 3 中的文件中。
- 完毕
推荐阅读
- apache-spark - PySpark SparkSession Builder 与 Kubernetes Master
- python - 想要删除提及时,带有 re.sub 的额外空间
- powershell - 主要组 ID Powershell 变量
- c - C 变量传输返回错误
- ruby-on-rails - 尝试使用设计注册用户时的 ActiveRecord::AssociationTypeMismatch
- python - GIMP Script-fu/Python-fu:对所有图层应用滤镜或颜色?
- c# - 捕捉到存储在 y 轴 Unity 中的相对旋转
- vba - 在用户窗体中初始化模块变量
- reactjs - react 16.3中的异步组件WillMount
- python - 在 Raspberry Pi3 上将数据从 Python 存储到 MySQL,无法获取和使用相同的数据