如何使用bigquery_datatransfer Python客户端创建AdWords BigQuery传输和传输运行?

时间:2018-10-29 15:57:12

标签: python google-bigquery

我已经能够成功进行身份验证,并列出转移和转移运行。但是我一直遇到由于传输配置不正确而无法创建传输的问题。

这是我尝试过的传输配置:

transferConfig = {
    'data_refresh_window_days': 1,
    'data_source_id': "adwords",
    'destination_dataset_id': "AdwordsMCC",
    'disabled': False,
    'display_name': "TestR",
    'name': "TestR",
    'schedule': "every day 07:00",
    'params': {
        "customer_id": "999999999" -- Changed Number
    }
}

response = client.create_transfer_config(parent, transferConfig)
print(response)

这是我得到的错误:

Traceback (most recent call last):
File "./create_transfer.py", line 84, in <module>
    main()
File "./create_transfer.py", line 61, in main
    response = client.create_transfer_config(parent, transferConfig)
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/cloud/bigquery_datatransfer_v1/gapic/data_transfer_service_client.py", line 438, in create_transfer_config
    authorization_code=authorization_code)
ValueError: Protocol message Struct has no "customer_id" field.
DDIS:bigquery siddharthsudheer$ ./create_transfer.py
Traceback (most recent call last):
File "./create_transfer.py", line 84, in <module>
    main()
File "./create_transfer.py", line 61, in main
    response = client.create_transfer_config(parent, transferConfig)
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/cloud/bigquery_datatransfer_v1/gapic/data_transfer_service_client.py", line 438, in create_transfer_config
    authorization_code=authorization_code)
ValueError: Protocol message Struct has no "customer_id" field.

1 个答案:

答案 0 :(得分:0)

通过将params定义为类google.protobuf.struct_pb2.Struct,我设法通过API设置了数据传输。

尝试添加以下内容是否适合您:

from google.protobuf.struct_pb2 import Struct

params = Struct()
params["customer_id"] = "999999999"

然后将您的transferConfig更改为:

transferConfig = {
    'data_refresh_window_days': 1,
    'data_source_id': "adwords",
    'destination_dataset_id': "AdwordsMCC",
    'disabled': False,
    'display_name': "TestR",
    'name': "TestR",
    'schedule': "every day 07:00",
    'params': params
    }
}