适用于 Python 的 Google Ads API:“_Rendezvous”对象没有属性“request_id”
Posted
技术标签:
【中文标题】适用于 Python 的 Google Ads API:“_Rendezvous”对象没有属性“request_id”【英文标题】:Google Ads API for Python: '_Rendezvous' object has no attribute 'request_id' 【发布时间】:2019-02-07 16:53:15 【问题描述】:我一直在尝试使用 Python 客户端库为 Google Ads API 复制以下代码示例。让我先说一下,我完成了身份验证过程并使用developer_token
、client_id
、client_secret
、refresh_token
和login_customer_id
配置了google-ads.yaml
文件。我希望复制的示例代码如下,您也可以在以下GitHub repository 中查看。
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This example illustrates how to get all campaigns.
To add campaigns, run add_campaigns.py.
"""
from __future__ import absolute_import
import argparse
import six
import sys
import google.ads.google_ads.client
_DEFAULT_PAGE_SIZE = 1000
def main(client, customer_id, page_size):
ga_service = client.get_service('GoogleAdsService')
query = ('SELECT campaign.id, campaign.name FROM campaign '
'ORDER BY campaign.id')
results = ga_service.search(customer_id, query=query,page_size=page_size)
try:
for row in results:
print('Campaign with ID %d and name "%s" was found.'
% (row.campaign.id.value, row.campaign.name.value))
except google.ads.google_ads.errors.GoogleAdsException as ex:
print('Request with ID "%s" failed with status "%s" and includes the '
'following errors:' % (ex.request_id, ex.error.code().name))
for error in ex.failure.errors:
print('\tError with message "%s".' % error.message)
if error.location:
for field_path_element in error.location.field_path_elements:
print('\t\tOn field: %s' % field_path_element.field_name)
sys.exit(1)
if __name__ == '__main__':
# GoogleAdsClient will read the google-ads.yaml configuration file in the
# home directory if none is specified.
google_ads_client = (google.ads.google_ads.client.GoogleAdsClient
.load_from_storage('google-ads.yaml'))
parser = argparse.ArgumentParser(
description='Lists all campaigns for specified customer.')
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The Google Ads customer ID.')
args = parser.parse_args()
main(google_ads_client, args.customer_id, _DEFAULT_PAGE_SIZE)
我尝试在命令提示符下以几种不同的方式运行上述代码,如下所示:
> python get_campaigns.py --customer_id 'xxx-xxx-xxxx'
> python get_campaign.py --customer_id 'xxxxxxxxxx'
我什至在声明 google_ads_client 变量后注释掉了这些行,并手动提供了客户 ID
main(google_ads_client, 'xxxxxxxxxx', _DEFAULT_PAGE_SIZE)
main(google_ads_client, 'xxx-xxx-xxxx', _DEFAULT_PAGE_SIZE)
并以这种方式运行脚本。对于所有这些情况,我仍然遇到同样的错误
AttributeError: '_Rendezvous' object has no attribute 'request_id'
任何帮助,将不胜感激。谢谢你。
【问题讨论】:
【参考方案1】:您实际上不需要定义或请求页面大小。你没有提供一个你需要但不提供的令牌。
考虑到您的查询只是请求广告系列、I'd suggest you use this version without the paging 或令牌需求(新的 Google Ads API 中不需要分页,除非您想自己实际实现分页,我不相信您会这样做)。
该版本将提供与第一个版本完全相同的结果,而无需分页。
【讨论】:
【参考方案2】:试试这个..
python get_campaigns.py --customer_id "123456789"
不带引号
【讨论】:
以上是关于适用于 Python 的 Google Ads API:“_Rendezvous”对象没有属性“request_id”的主要内容,如果未能解决你的问题,请参考以下文章
Google Ads API 的 Google OAuth 问题 - python
Python:Google Ads API 错误(TargetingIdeaService INVALID_SEARCH_PARAMETERS)
是否有适用于 Python 3.x 的 Google 数据 API (gdata)?
适用于 Python 和 AWS Lambda 的 Google Cloud Platform API 不兼容:无法导入名称“cygrpc”
python 适用于Google云端硬盘的Python终端客户端,可轻松上传,删除,列出,共享文件或文件夹。 (参见评论中的用法)