【发布时间】:2020-05-30 20:28:22
【问题描述】:
我的步骤:
-
获取授权码:我用这个网址获取授权码
https://www.gstatic.com/bigquerydatatransfer/oauthz/auth?clientId=<id from list data sources>&scope=https://www.googleapis.com/auth/adwords%20https://www.googleapis.com/auth/bigquery 使用项目所有者创建服务帐户
- 执行示例代码:
def run_quickstart():
from google.cloud import bigquery_datatransfer_v1
from google.protobuf.struct_pb2 import Struct
client = bigquery_datatransfer_v1.DataTransferServiceClient()
project = <project-id>
parent = client.location_path(project, 'us')
params = Struct()
params.update({
"customer_id": <customer-id>
})
transfer_config = {
"destination_dataset_id": "test",
"display_name": "test",
"data_source_id": "adwords",
"params": params
}
authorization_code = <authorization_code from step 1>
response = client.create_transfer_config(parent, transfer_config, authorization_code)
print(response)
if __name__ == '__main__':
run_quickstart()
期望:数据传输创建 但是我得到了错误:
Traceback (most recent call last):
File "/project/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
return callable_(*args, **kwargs)
File "/project/lib/python3.7/site-packages/grpc/_channel.py", line 826, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "/project/lib/python3.7/site-packages/grpc/_channel.py", line 729, in _end_unary_response_blocking
raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.INVALID_ARGUMENT
details = "Request contains an invalid argument."
debug_error_string = "{"created":"@1581747953.387292000","description":"Error received from peer ipv6:[2404:6800:4012:1::200a]:443","file":"src/core/lib/surface/call.cc","file_line":1056,"grpc_message":"Request contains an invalid argument.","grpc_status":3}"
>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "app.py", line 49, in <module>
run_quickstart()
File "app.py", line 40, in run_quickstart
parent, transfer_config, authorization_code)
File "/project/lib/python3.7/site-packages/google/cloud/bigquery_datatransfer_v1/gapic/data_transfer_service_client.py", line 563, in create_transfer_config
request, retry=retry, timeout=timeout, metadata=metadata
File "/project/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py", line 143, in __call__
return wrapped_func(*args, **kwargs)
File "/project/lib/python3.7/site-packages/google/api_core/retry.py", line 286, in retry_wrapped_func
on_error=on_error,
File "/project/lib/python3.7/site-packages/google/api_core/retry.py", line 184, in retry_target
return target()
File "/project/lib/python3.7/site-packages/google/api_core/timeout.py", line 214, in func_with_timeout
return func(*args, **kwargs)
File "/project/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument.
我找不到哪一步是错误的。请帮我弄清楚。
--- 02-19 更新
@mk_sta
我删除 authorization_code 然后 API 可以创建传输,但传输无法进行。它会得到一个像这个截图一样的错误。
我认为错误是由authorization_code 用于连接谷歌广告引起的。您的转接工作正常吗?
参考:
【问题讨论】:
-
您是否尝试过针对 BigQuery 数据传输 API 更改身份验证方法,即设置
GOOGLE_APPLICATION_CREDENTIALS环境变量而不是使用 OAuth2 授权代码?还是一样的问题吗? -
@mk_sta 是的,我已经设置了环境
GOOGLE_APPLICATION_CREDENTIALS
标签: python google-cloud-platform google-bigquery transfer google-api-python-client