KeyError:' rowCount'适用于Reporting API v4中的选定客户端

时间:2017-02-17 17:29:32

标签: python

运行我们新实施的Reporting API v4时出现此错误 它为大多数客户成功运行,但是对于少数客户来说会遇到此错误。当我有点陷入困境时,我会非常乐意帮助搞清楚。

Traceback (most recent call last):
File "v4analytics.py", line 424, in <module>
main()
File "v4analytics.py", line 420, in main
extract_all(service)
File "v4analytics.py", line 146, in extract_all
for profile_results in run_queries_per_day(service, profile_id, profile_name):
File "v4analytics.py", line 205, in run_queries_per_day
print 'rowCount: %s' % results['reports'][0]['data']['rowCount']
KeyError: 'rowCount'

错误来自这部分代码:

def run_queries_per_day(service, profile_id, profile_name):
""" Runs the query for one profile and return the data """
start_date = parse_date(settings.START_DATE)
end_date = parse_date(settings.END_DATE)
date_range = end_date - start_date
for day_delta in range(0, date_range.days + 1):
current_day = start_date + timedelta(day_delta)
print 'Day: %s' % current_day

has_next = True
next_page_token = '0'
while has_next:
# temp fix for 429 RESOURCE_EXHAUSTED AnalyticsDefaultGroupUSER-100s:
time.sleep(settings.WAIT_BETWEEN_REQUESTS_SECONDS)
query = build_query(service,
profile_id,
format_date(current_day),
format_date(current_day),
next_page_token=next_page_token,
)
results = query.execute()

next_page_token = results['reports'][0].get('nextPageToken')
if not next_page_token:
has_next = False

print 'rowCount: %s' % results['reports'][0]['data']['rowCount']
if contains_sampled_data(results):
with open(settings.SAMPLEDDATA_FILE, 'a') as sample_file:
sample_file.write('profile_id: %s\n' % profile_id)
sample_file.write('profile_name: %s\n' % profile_name)
sample_file.write('\n')

yield build_response(results, profile_id, profile_name)
print

感谢您的帮助

0 个答案:

没有答案