如何从Python MWS中的xml get_report_request_list()解析XML响应中的报告?

时间:2019-05-05 05:46:37

标签: python-3.x amazon-mws

使用Python 3.6和MWS库从Amazon MWS api中提取报告。

我试图遍历list_of_reports对象中的报告,并找到与我请求的报告“完成”匹配的报告。

图书馆在这里:https://github.com/czpython/python-amazon-mws/blob/master/mws/mws.py

相关行:

    def get_report_request_list(self, requestids=(), types=(), processingstatuses=(),
                                max_count=None, fromdate=None, todate=None):
        data = dict(Action='GetReportRequestList',
                    MaxCount=max_count,
                    RequestedFromDate=fromdate,
                    RequestedToDate=todate)
        data.update(self.enumerate_param('ReportRequestIdList.Id.', requestids))
        data.update(self.enumerate_param('ReportTypeList.Type.', types))
        data.update(self.enumerate_param('ReportProcessingStatusList.Status.', processingstatuses))
        return self.make_request(data)

Amazon文档流程图:http://docs.developer.amazonservices.com/en_US/reports/Reports_Overview.html

#!/usr/bin/env python3.6
# -*- coding: utf-8 -*-

import csv
import io
import mws

access_key = 'XXX'
merchant_id = 'XXX'
secret_key = 'XXX'
marketplace_id = '00'
report_id = '_GET_AMAZON_FULFILLED_SHIPMENTS_DATA_'

def get_report(access_key, secret_key, merchant_id, marketplace_id, report_type):
    x = mws.Reports(access_key=access_key, secret_key=secret_key, account_id=merchant_id)    
    x.request_report(report_type)
    reports = x.get_report_request_list()
    for report in reports.GetReportRequestListResponse.GetReportRequestListResult.ReportRequestInfo:
        if report.ReportProcessingStatus == '_DONE_' and report.ReportType == report_type:
    pass

get_report(access_key=access_key, secret_key=secret_key, merchant_id=merchant_id, marketplace_id=marketplace_id, report_type=report_id)

尝试遍历get_report_request_list()响应时,出现属性错误“'DictWrapper'对象没有属性'GetReportRequestListResponse'”。

您知道为什么以及如何纠正它吗?

0 个答案:

没有答案