Skip to content

urllib2.URLError: <urlopen error [Errno 10054] #251

Closed
@chaitu1124

Description

@chaitu1124

Hi,
Very frequently I was facing this issue. My company have total 275 accounts so I was looping each and every account to pull the SHOPPING_PERFORMACE_REPORT. In windows I was facing issues with parallel report.

I was getting the following error.

Traceback (most recent call last):
  File "get_campaigns_new2.py", line 138, in <module>
    main(adwords_client)
  File "get_campaigns_new2.py", line 130, in main
    download_Performance_Criteria_Report()
  File "get_campaigns_new2.py", line 100, in download_Performance_Criteria_Report
    rep_downloader = client.GetReportDownloader(version='v201710')
  File "C:\Python27\lib\site-packages\googleads\adwords.py", line 506, in GetReportDownloader
    return ReportDownloader(self, version, server)
  File "C:\Python27\lib\site-packages\googleads\adwords.py", line 1305, in __init__
    cache=self._adwords_client.cache).wsdl.schema
  File "C:\Python27\lib\site-packages\suds\client.py", line 115, in __init__
    self.wsdl = reader.open(url)
  File "C:\Python27\lib\site-packages\suds\reader.py", line 150, in open
    d = self.fn(url, self.options)
  File "C:\Python27\lib\site-packages\suds\wsdl.py", line 136, in __init__
    d = reader.open(url)
  File "C:\Python27\lib\site-packages\suds\reader.py", line 74, in open
    d = self.download(url)
  File "C:\Python27\lib\site-packages\suds\reader.py", line 92, in download
    fp = self.options.transport.open(Request(url))
  File "C:\Python27\lib\site-packages\suds\transport\http.py", line 67, in open
    return self.u2open(u2request)
  File "C:\Python27\lib\site-packages\suds\transport\http.py", line 132, in u2open
    return url.open(u2request, timeout=tm)
  File "C:\Python27\lib\urllib2.py", line 429, in open
    response = self._open(req, data)
  File "C:\Python27\lib\urllib2.py", line 447, in _open
    '_open', req)
  File "C:\Python27\lib\urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "C:\Python27\lib\urllib2.py", line 1241, in https_open
    context=self._context)
  File "C:\Python27\lib\urllib2.py", line 1198, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 10054] An existing connection was forcibly closed by the remote host>

Code:

def download_Performance_Criteria_Report():
  CHUNK_SIZE = 16 * 1024
  accounts_processed="D:/adwords/temp/accounts_processed.txt"
  ap=[]
  if os.path.exists(accounts_processed):
      with open('D:/adwords/temp/accounts_processed.txt','r') as f:
          ap = [line.strip() for line in f]
  with open('D:/adwords/temp/accounts_processed.txt','ab') as f:
      ap = map(int, ap)
      print ap
      for client_customer_id in list(set(account_list)):
        print client_customer_id
        if client_customer_id not in ap:
            print "hi"
            o2client = GoogleRefreshTokenClient(adc['client_id'],adc['client_secret'],adc['refresh_token'])
            client=AdWordsClient(adc['developer_token'],o2client,'OBI',client_customer_id=client_customer_id)
            _fpath=os.path.join('D:/adwords/temp/Adwords_Shopping_MMA_'+str(client_customer_id)+'_'+time.strftime( "%Y%m%d") + '.csv')
          ##    client = AdWordsClient.LoadFromStorage('googleads.yaml')
            rep_downloader = client.GetReportDownloader(version='v201710')
            report = {
                    'reportName' : 'SHOPPING_PERFORMANCE_REPORT',
                    'dateRangeType' :'CUSTOM_DATE',
                    'reportType': 'SHOPPING_PERFORMANCE_REPORT',
                    'downloadFormat': 'CSV',
                    'selector': {
                        'fields': ['AccountDescriptiveName','AdGroupId','AdGroupName','AggregatorId','Brand','CampaignId','CampaignName','CategoryL1','CategoryL2','CategoryL3','CategoryL4','CategoryL5','CountryCriteriaId','CustomAttribute0','CustomAttribute1','CustomAttribute2','CustomAttribute3','CustomAttribute4','ExternalCustomerId','LanguageCriteriaId','MerchantId','OfferId','ProductTypeL1','ProductTypeL2','ProductTypeL3','ProductTypeL4','ProductTypeL5','StoreId','Date','AverageCpc','Clicks','ConversionRate','Conversions','ConversionValue','Cost','CostPerAllConversion','CostPerConversion','CrossDeviceConversions','Ctr','Impressions'],
                        'dateRange' : { 'min': '20180125' , 'max' : '20180205'},
                        }
                    }
            _f=open(_fpath,'wb')
##            rep_downloader.DownloadReport(report,output=_f,skip_report_header=False,skip_column_header=False,skip_report_summary=True)
            report_data = StringIO.StringIO()
            stream_data = rep_downloader.DownloadReportAsStream(report,skip_report_header=False, skip_column_header=False, skip_report_summary=True, include_zero_impressions=False)
            try:
                while True:
                    chunk = stream_data.read(CHUNK_SIZE)
                    if not chunk: break
                    report_data.write(chunk.decode() if sys.version_info[0] == 3  and getattr(report_data, 'mode', 'w') == 'w' else chunk)
                _f.write(report_data.getvalue())
            finally:
                report_data.close()
                stream_data.close()
            f.write(str(client_customer_id)+"\n")

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions