我正在尝试让 Python 的 Google Cloud Platform Data Loss Prevention (DLP) 客户端库在 SSL 代理后面工作: https ://cloud.google.com/dlp/docs/libraries#client-libraries-usage-python
我正在使用文档中的代码片段:
# Import the client library
import google.cloud.dlp
import os
import subprocess
import json
import requests
import getpass
import urllib.parse
import logging
logging.basicConfig(level=logging.DEBUG)
# Instantiate a client.
dlp_client = google.cloud.dlp.DlpServiceClient()
# The string to inspect
content = 'Robert Frost'
# Construct the item to inspect.
item = {'value': content}
# The info types to search for in the content. Required.
info_types = [{'name': 'FIRST_NAME'}, {'name': 'LAST_NAME'}]
# The minimum likelihood to constitute a match. Optional.
min_likelihood = 'LIKELIHOOD_UNSPECIFIED'
# The maximum number of findings to report (0 = server maximum). Optional.
max_findings = 0
# Whether to include the matching string in the results. Optional.
include_quote = True
# Construct the configuration dictionary. Keys which are None may
# optionally be omitted entirely.
inspect_config = {
'info_types': info_types,
'min_likelihood': min_likelihood,
'include_quote': include_quote,
'limits': {'max_findings_per_request': max_findings},
}
# Convert the project id into a full resource id.
parent = dlp_client.project_path('my-project-id')
# Call the API.
response = dlp_client.inspect_content(parent, inspect_config, item)
# Print out the results.
if response.result.findings:
for finding in response.result.findings:
try:
print('Quote: {}'.format(finding.quote))
except AttributeError:
pass
我还设置了以下 ENV 变量:
GOOGLE_APPLICATION_CREDENTIALS
当您不在 SSL 代理后面时,它可以毫无问题地运行。当我在代理后面工作时,我正在设置 3 个 ENV 变量:
REQUESTS_CA_BUNDLE
HTTP_PROXY
HTTPS_PROXY
通过这样的设置,其他 GCP 客户端 python 库可以在 SSL 代理后面正常工作,例如用于存储或 bigquery)。
我没有在文档中找到解释该库是否与代理一起作为一个 GCP 客户端库以及如何将其配置为与 SSL 代理一起使用的文档。该库处于测试阶段,因此可能尚未实现。
它似乎与 CA 证书和握手有关。BigQuery 和 Storage Client python lib 使用相同的 CA 没有问题。任何想法 ?
蓝山帝景
桃花长相依
相关分类