BingAds / BingAds-Python-SDK

Other
118 stars 164 forks source link

suds.WebFault: Server raised fault: 'Invalid client data. Check the SOAP fault details for more information. TrackingId: 50f4b6a7-b48f-43d1-b1ba-f5bd5d9fc779.' #276

Open Beyond-me opened 7 months ago

Beyond-me commented 7 months ago

I want to obtain the account performance report through the Python SDK, but it is not included in the example. Therefore, I followed the example and wrote this part of the code. The report in the example can run normally and download successfully, but the code I wrote cannot download the report properly. May I ask where I made a mistake? My code is as follows what should I do

from auth_helper import from bingads import AuthorizationData from bingads.v13.reporting import from output_helper import output_bing_ads_webfault_error, output_webfault_errors, output_status_message from auth_helper import authenticate

REPORT_FILE_FORMAT='Csv' FILE_DIRECTORY='reports' RESULT_FILE_NAME='result.' + REPORT_FILE_FORMAT.lower() TIMEOUT_IN_MILLISECONDS=3600000

def main(authorization_data): report_request=get_report_request(authorization_data.account_id) reporting_download_parameters = ReportingDownloadParameters( report_request=report_request, result_file_directory = FILE_DIRECTORY, result_file_name = RESULT_FILE_NAME, overwrite_result_file = True, # Set this value true if you want to overwrite the same file. timeout_in_milliseconds=TIMEOUT_IN_MILLISECONDS # You may optionally cancel the download after a specified time interval. ) output_status_message("-----\nAwaiting download_report...") download_report(reporting_download_parameters)

def background_completion(reporting_download_parameters): global reporting_service_manager result_file_path = reporting_service_manager.download_file(reporting_download_parameters) output_status_message("Download result file: {0}".format(result_file_path))

def submit_and_download(report_request): global reporting_service_manager reporting_download_operation = reporting_service_manager.submit_download(report_request)

reporting_operation_status = reporting_download_operation.track(timeout_in_milliseconds=TIMEOUT_IN_MILLISECONDS)

result_file_path = reporting_download_operation.download_result_file(
    result_file_directory = FILE_DIRECTORY,
    result_file_name = RESULT_FILE_NAME,
    decompress = True,
    overwrite = True,  # Set this value true if you want to overwrite the same file.
    timeout_in_milliseconds=TIMEOUT_IN_MILLISECONDS # You may optionally cancel the download after a specified time interval.
)

output_status_message("Download result file: {0}".format(result_file_path))

def download_results(request_id, authorization_data): reporting_download_operation = ReportingDownloadOperation( request_id = request_id, authorization_data=authorization_data, poll_interval_in_milliseconds=1000, environment=ENVIRONMENT, )

reporting_operation_status = reporting_download_operation.track(timeout_in_milliseconds=TIMEOUT_IN_MILLISECONDS)

result_file_path = reporting_download_operation.download_result_file(
    result_file_directory = FILE_DIRECTORY,
    result_file_name = RESULT_FILE_NAME,
    decompress = True,
    overwrite = True,  # Set this value true if you want to overwrite the same file.
    timeout_in_milliseconds=TIMEOUT_IN_MILLISECONDS # You may optionally cancel the download after a specified time interval.
)

output_status_message("Download result file: {0}".format(result_file_path))
output_status_message("Status: {0}".format(reporting_operation_status.status))

def download_report(reporting_download_parameters): global reporting_service_manager

report_container = reporting_service_manager.download_report(reporting_download_parameters)

if(report_container == None):
    output_status_message("There is no report data for the submitted report request parameters.")
    sys.exit(0)

report_container.close()

def get_report_request(account_id): """ Use a sample report request or build your own. """

aggregation = 'Summary'
exclude_column_headers=False
exclude_report_footer=False
exclude_report_header=False
time=reporting_service.factory.create('ReportTime')
# You can either use a custom date range or predefined time.
time.PredefinedTime='LastMonth'
time.ReportTimeZone='PacificTimeUSCanadaTijuana'
time.CustomDateRangeStart = None
time.CustomDateRangeEnd = None
return_only_complete_data=False

account_performance_report_request = get_account_performance_report_request(
    account_id=account_id,
    aggregation=aggregation,
    exclude_column_headers=exclude_column_headers,
    exclude_report_footer=exclude_report_footer,
    exclude_report_header=exclude_report_header,
    report_file_format=REPORT_FILE_FORMAT,
    return_only_complete_data=return_only_complete_data,
    time=time)

return account_performance_report_request

def get_account_performance_report_request( account_id, aggregation, exclude_column_headers, exclude_report_footer, exclude_report_header, report_file_format, return_only_complete_data, time): report_request=reporting_service.factory.create('AccountPerformanceReportRequest') report_request.Aggregation=aggregation report_request.ExcludeColumnHeaders=exclude_column_headers report_request.ExcludeReportFooter=exclude_report_footer report_request.ExcludeReportHeader=exclude_report_header report_request.Format=report_file_format report_request.ReturnOnlyCompleteData=return_only_complete_data report_request.Time=time report_request.ReportName = "My Account Performance Report" scope = reporting_service.factory.create('AccountReportScope') scope.AccountIds={'long': [account_id] } report_request.Scope=scope

scope.Campaigns=None

report_columns=reporting_service.factory.create('ArrayOfAccountPerformanceReportColumn')
report_columns.AccountPerformanceReportColumn.append([
    'AccountName',
    # 'CurrencyCode',
    # 'Ctr',
    # 'AverageCpc',
    # 'Conversions',
    # 'Impressions',
    # 'Clicks',
    # 'Spend'
])
report_request.Columns=report_columns

return report_request

if name == 'main':

print("Loading the web service client proxies...")
ENVIRONMENT = 'production'
developerToken = 'xxxxxxxxxxxxxxxx'
CustomerId = xxxxxxxxx
accountid = xxxxxxxxx

authorization_data=AuthorizationData(
    account_id=accountid,
    customer_id=CustomerId,
    developer_token=developerToken,
    authentication=accessToken,
)

reporting_service_manager=ReportingServiceManager(
    authorization_data=authorization_data,
    poll_interval_in_milliseconds=5000,
    environment=ENVIRONMENT,
)

reporting_service=ServiceClient(
    service='ReportingService',
    version=13,
    authorization_data=authorization_data,
    environment=ENVIRONMENT,
)

authenticate(authorization_data)
main(authorization_data)
Beyond-me commented 7 months ago

The complete error prompt is as follows:

Loading the web service client proxies...

Awaiting download_report... Web service reported a SOAP processing fault using an unexpected HTTP status code 200. Reporting as an internal server error. Traceback (most recent call last): File "E:/LQ_JOB/advertising_channel/bing/BingAds-Python-SDK-main/examples/v13/report_requests.py", line 543, in main(authorization_data) File "E:/LQ_JOB/advertising_channel/bing/BingAds-Python-SDK-main/examples/v13/report_requests.py", line 70, in main download_report(reporting_download_parameters) File "E:/LQ_JOB/advertising_channel/bing/BingAds-Python-SDK-main/examples/v13/report_requests.py", line 154, in download_report report_container = reporting_service_manager.download_report(reporting_download_parameters) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\bingads\v13\reporting\reporting_service_manager.py", line 59, in download_report report_file_path = self.download_file(download_parameters) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\bingads\v13\reporting\reporting_service_manager.py", line 75, in download_file operation = self.submit_download(download_parameters.report_request) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\bingads\v13\reporting\reporting_service_manager.py", line 102, in submit_download response = self.service_client.SubmitGenerateReport(report_request) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\bingads\service_client.py", line 286, in call raise ex File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\bingads\service_client.py", line 278, in call response = self.service_client.soap_client.service.getattr(self.name)(*args, **kwargs) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\suds\client.py", line 586, in call return client.invoke(args, kwargs) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\suds\client.py", line 728, in invoke result = self.send(soapenv, timeout=timeout) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\suds\client.py", line 777, in send return self.process_reply(reply.message, None, None) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\suds\client.py", line 840, in process_reply raise WebFault(fault, replyroot) suds.WebFault: Server raised fault: 'Invalid client data. Check the SOAP fault details for more information. TrackingId: 50f4b6a7-b48f-43d1-b1ba-f5bd5d9fc779.'

Process finished with exit code 1