0

我有一些(工作的)Python 3.5.2 代码可以通过他们的 API 从 Bing Ads 下载报告,我正试图将其放入 Django 应用程序中。

当我通过 Django shell 运行代码时,在调用 SubmitGenerateReport(ReportRequest=report_request) 后,我收到此错误:

Traceback (most recent call last):
  File "C:\Python35-32\lib\site-packages\googleads\util.py", line 123, in PatchedHttpTransportSend
    fp = self.u2open(u2request)
  File "C:\Python35-32\lib\site-packages\suds\transport\http.py", line 132, in u2open
    return url.open(u2request, timeout=tm)
  File "C:\Python35-32\lib\urllib\request.py", line 472, in open
    response = meth(req, response)
  File "C:\Python35-32\lib\urllib\request.py", line 582, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Python35-32\lib\urllib\request.py", line 510, in error
    return self._call_chain(*args)
  File "C:\Python35-32\lib\urllib\request.py", line 444, in _call_chain
    result = func(*args)
  File "C:\Python35-32\lib\urllib\request.py", line 590, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Internal Server Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python35-32\lib\site-packages\suds\client.py", line 613, in send
    reply = self.options.transport.send(request)
  File "C:\Python35-32\lib\site-packages\suds\transport\https.py", line 66, in send
    return HttpTransport.send(self, request)
  File "C:\Python35-32\lib\site-packages\googleads\util.py", line 134, in PatchedHttpTransportSend
    raise suds.transport.TransportError(e.msg, e.code, e.fp)
suds.transport.TransportError: Internal Server Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Users\joe.heffer\PycharmProjects\wisepanda\report\models.py", line 401, in query
    report_submission = reporting_service_client.SubmitGenerateReport(ReportRequest=report_request)
  File "C:\Python35-32\lib\site-packages\bingads\service_client.py", line 269, in __call__
    raise ex
  File "C:\Python35-32\lib\site-packages\bingads\service_client.py", line 261, in __call__
    response = self.service_client.soap_client.service.__getattr__(self.name)(*args, **kwargs)
  File "C:\Python35-32\lib\site-packages\suds\client.py", line 521, in __call__
    return client.invoke(args, kwargs)
  File "C:\Python35-32\lib\site-packages\suds\client.py", line 581, in invoke
    result = self.send(soapenv)
  File "C:\Python35-32\lib\site-packages\suds\client.py", line 619, in send
    description=tostr(e), original_soapenv=original_soapenv)
  File "C:\Python35-32\lib\site-packages\suds\client.py", line 670, in process_reply
    raise WebFault(fault, replyroot)
suds.WebFault: Server raised fault: 'The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter https://bingads.microsoft.com/Reporting/v11:ReportRequest. The InnerException message was 'There was an error deserializing the object of type Microsoft.AdCenter.Advertiser.Reporting.Api.DataContracts.Request.ReportRequest. The value '' cannot be parsed as the type 'Int32'.'.  Please see InnerException for more details.'

我找不到我的 SOAP 请求的问题:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="https://bingads.microsoft.com/Reporting/v11" xmlns:ns1="https://bingads.microsoft.com/Reporting/v11" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header>
      <tns:CustomerAccountId>135071005</tns:CustomerAccountId>
      <tns:CustomerId>257199989</tns:CustomerId>
      <tns:DeveloperToken>BBD37VB98</tns:DeveloperToken>
      <tns:Password>*************</tns:Password>
      <tns:UserName>joe_heffer_sbx</tns:UserName>
   </SOAP-ENV:Header>
   <ns0:Body>
      <ns1:SubmitGenerateReportRequest>
         <ns1:ReportRequest xsi:type="ns1:KeywordPerformanceReportRequest">
            <ns1:ExcludeColumnHeaders>false</ns1:ExcludeColumnHeaders>
            <ns1:ExcludeReportFooter>true</ns1:ExcludeReportFooter>
            <ns1:ExcludeReportHeader>true</ns1:ExcludeReportHeader>
            <ns1:Format>Csv</ns1:Format>
            <ns1:Language>English</ns1:Language>
            <ns1:ReportName>Bing Report</ns1:ReportName>
            <ns1:ReturnOnlyCompleteData>false</ns1:ReturnOnlyCompleteData>
            <ns1:Aggregation>Daily</ns1:Aggregation>
            <ns1:Columns>
               <ns1:KeywordPerformanceReportColumn>TimePeriod</ns1:KeywordPerformanceReportColumn>
               <ns1:KeywordPerformanceReportColumn>Spend</ns1:KeywordPerformanceReportColumn>
            </ns1:Columns>
            <ns1:Filter>
               <ns1:AdRelevance/>
               <ns1:ExpectedCtr/>
               <ns1:Keywords/>
               <ns1:LandingPageExperience/>
               <ns1:LanguageCode/>
               <ns1:QualityScore/>
            </ns1:Filter>
            <ns1:Scope/>
            <ns1:Sort/>
            <ns1:Time>
               <ns1:CustomDateRangeEnd>
                  <ns1:Day/>
                  <ns1:Month/>
                  <ns1:Year/>
               </ns1:CustomDateRangeEnd>
               <ns1:CustomDateRangeStart>
                  <ns1:Day/>
                  <ns1:Month/>
                  <ns1:Year/>
               </ns1:CustomDateRangeStart>
               <ns1:PredefinedTime>ThisYear</ns1:PredefinedTime>
            </ns1:Time>
         </ns1:ReportRequest>
      </ns1:SubmitGenerateReportRequest>
   </ns0:Body>
</SOAP-ENV:Envelope>

我认为线索可能是我收到提到 Google 的 suds 错误(也为此 Django 应用程序安装了 Google API(也使用 suds)。)

4

1 回答 1

0

问题是我的报告请求指定了自定义日期范围参数和预定义的日期范围。

这是由 Microsoft 技术人员在其论坛上确定的:

https://social.msdn.microsoft.com/Forums/en-US/9dc7be19-9ac7-4cba-8472-e79300cd6655/webfault-deserialize-parameter-in-python?forum=BingAds

解决方案是这样的:

# Build report request
report_request = reporting_service_client.factory.create('KeywordPerformanceReportRequest')
# Time range
report_time = reporting_service_client.factory.create('ReportTime')
report_time.PredefinedTime = 'ThisYear'
del report_time.CustomDateRangeEnd
del report_time.CustomDateRangeStart
于 2017-11-10T14:35:46.870 回答