python - BigQuery DataTransfer:StartManualTransferRunsRequest 的构造函数输入无效
问题描述
我正在尝试通过 GCP 中的云函数触发计划查询。我尝试遵循几个教程和示例并浏览了文档,但是使用新版本的 APIgoogle-cloud-bigquery-datatransfer==3.1.1
我找不到任何显示正确程序的内容。
您将在我当前的代码下方找到:
from google.cloud import bigquery_datatransfer_v1
def triggerQuery (parent, requested_run_time):
client = bigquery_datatransfer_v1.DataTransferServiceClient()
project_id = '###' # Enter your projectID here
location_id = 'europe' # Enter your locationID here
transfer_id = '###' # Enter your transferId here
transfer_config = {...}
path = f"projects/{project_id}/locations/{location_id}/transferConfigs/{transfer_id}"
parent = client.transfer_config_path(project_id, transfer_id)
response = client.start_manual_transfer_runs(path)
print(response)
我尝试传递给client.start_manual_transfer_runs
或path
但parent
我得到:
TypeError: Invalid constructor input for StartManualTransferRunsRequest: 'projects/###/locations/europe/transferConfigs/###'
我还需要指定 Cloud Function 与有权在 BigQuery 中运行查询的正确服务帐户相关联。
帮助将不胜感激!
解决方案
您需要以字典格式输入手动传输运行的参数。下面的代码对我有用:
import time
from google.cloud import bigquery_datatransfer_v1
from google.protobuf.timestamp_pb2 import Timestamp
client = bigquery_datatransfer_v1.DataTransferServiceClient()
project_id = 'your-project-id'
transfer_config_id = 'config-id-can-be-found-in-ui'
location = 'location-of-your-transfer-config'
start_time = Timestamp(seconds=int(time.time()+20))
parent = f'projects/{project_id}/locations/{location}/transferConfigs/{transfer_config_id}'
response = client.start_manual_transfer_runs({"parent": parent, "requested_run_time": start_time})
print(response)
推荐阅读
- javascript - 指数分布地形的细节
- php - 如何在 tpl 文件中调用 tcpdf 非静态方法
- python - scipy.optimize 矩阵约束问题
- django - 将域路径添加到 django html 模板
- javascript - 是否有任何更新来修复警告“ViewPager Android 已从 react-native 核心中提取”?
- keycloak - 向 JWT 添加声明的 Keycloak 协议映射器获取空指针异常
- laravel - 显示每个 b 表行的模式的按钮
- sql - 当我添加带有匕首 † 符号的 where 子句时,我的查询失败
- python-3.x - 为什么回调发生在执行开始时,甚至在事件之后?
- javascript - 断言文件下载的 Testcafe 示例