BingAds / BingAds-Python-SDK

Other
116 stars 162 forks source link

Error: requests.exceptions.ConnectionError: Max retries exceeded with url: /ReportDownload/Download.aspx... #10

Closed iamdoron closed 8 years ago

iamdoron commented 8 years ago

Hi,

once in a while I get the following error while using the bulk service (similar code to the provided example) to get keywords (it also happens with other entities):

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='download.api.bingads.microsoft.com', port=443): Max retries exceeded with url: /ReportDownload/Download.aspx?q=<obscurified> (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f7c2d6ef210>: Failed to establish a new connection: [Errno -2] Name or service not known',))

----- Python Traceback -----
File "<obscurified>", line <obscurified>, in <module>
  background_completion(reporting_download_parameters)
File "<obscurified>", line <obscurified>, in background_completion
  result_file_path = reporting_service_manager.download_file(reporting_download_parameters)
File "/usr/local/lib/python2.7/dist-packages/bingads/reporting/reporting_service_manager.py", line 65, in download_file
  overwrite=download_parameters.overwrite_result_file,
File "/usr/local/lib/python2.7/dist-packages/bingads/reporting/reporting_operation.py", line 103, in download_result_file
  r = s.get(url, headers=headers, stream=True, verify=True)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 480, in get
  return self.request('GET', url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 468, in request
  resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 576, in send
  r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 437, in send
  raise ConnectionError(e, request=request)

sometimes I get similar error, but it in different places within the SDK

  File "<obscurified>", line <obscurified>, in background_completion
    result_file_path = reporting_service_manager.download_file(reporting_download_parameters)
  File "/usr/local/lib/python2.7/dist-packages/bingads/reporting/reporting_service_manager.py", line 57, in download_file
    operation.track()
  File "/usr/local/lib/python2.7/dist-packages/bingads/reporting/reporting_operation.py", line 135, in track
    status = self.get_status()
  File "/usr/local/lib/python2.7/dist-packages/bingads/reporting/reporting_operation.py", line 153, in get_status
    response = self.service_client.PollGenerateReport(self.request_id)
  File "/usr/local/lib/python2.7/dist-packages/bingads/service_client.py", line 269, in __call__
    raise ex

From what I understand the server says it gets too many requests. It might be worth to catch this exception, sleep, and try again within the SDK. It can be done from the outside but then a new request will be generated for no reason.

imagineful commented 8 years ago

thanks for your feedback. recently we are trying to add retry logic to bulk and report service. it would be available in 10.4.2. And one thing to confirm, does it happen on Bulk service or Reporting service, or both? from the exceptions, it seems it was Reporting service (reporting_service_manager.py) Thanks.

iamdoron commented 8 years ago

Yes, it happened also with the bulk service but I can't find the stack trace for it

iamdoron commented 8 years ago
   result_file_path = bulk_service.download_file(download_parameters, progress = None)
    File "/usr/local/lib/python2.7/dist-packages/bingads/v10/bulk/bulk_service_manager.py", line 70, in download_file
      operation.track(progress)
    File "/usr/local/lib/python2.7/dist-packages/bingads/v10/bulk/bulk_operation.py", line 206, in track
      status = self.get_status()
    File "/usr/local/lib/python2.7/dist-packages/bingads/v10/bulk/bulk_operation.py", line 227, in get_status
      response = self.service_client.GetBulkDownloadStatus(RequestId=self.request_id)
    File "/usr/local/lib/python2.7/dist-packages/bingads/service_client.py", line 269, in __call__
      raise ex
imagineful commented 8 years ago

@iamdoron we have added retry mechanism in get_status function in version 10.4.2. do you still see this error happening?

Thanks. Li.

imagineful commented 8 years ago

close issue, if any problem, please feel free to let us know. Thanks.