1313from scrapy_zyte_smartproxy .utils import exp_backoff
1414
1515
16+ logger = logging .getLogger (__name__ )
17+
18+
1619class ZyteSmartProxyMiddleware (object ):
1720
1821 url = 'http://proxy.zyte.com:8011'
@@ -71,15 +74,15 @@ def open_spider(self, spider):
7174 return
7275
7376 if not self .apikey :
74- logging .warning (
77+ logger .warning (
7578 "Zyte Smart Proxy Manager cannot be used without an API key" ,
7679 extra = {'spider' : spider },
7780 )
7881 return
7982
8083 self ._proxyauth = self .get_proxyauth (spider )
8184
82- logging .info (
85+ logger .info (
8386 "Using Zyte Smart Proxy Manager at %s (apikey: %s)" % (
8487 self .url , self .apikey [:7 ]
8588 ),
@@ -89,7 +92,7 @@ def open_spider(self, spider):
8992 if not self .preserve_delay :
9093 # Setting spider download delay to 0 to get maximum crawl rate
9194 spider .download_delay = 0
92- logging .info (
95+ logger .info (
9396 "ZyteSmartProxyMiddleware: disabling download delays in "
9497 "Scrapy to optimize delays introduced by Zyte Smart Proxy "
9598 "Manager. To avoid this behaviour you can use the "
@@ -130,9 +133,9 @@ def _get_setting_value(self, spider, k, type_):
130133
131134 def _fix_url_protocol (self ):
132135 if self .url .startswith ('https://' ):
133- logging .warning ('ZYTE_SMARTPROXY_URL "%s" set with "https://" protocol.' % self .url )
136+ logger .warning ('ZYTE_SMARTPROXY_URL "%s" set with "https://" protocol.' % self .url )
134137 elif not self .url .startswith ('http://' ):
135- logging .warning ('Adding "http://" to ZYTE_SMARTPROXY_URL %s' % self .url )
138+ logger .warning ('Adding "http://" to ZYTE_SMARTPROXY_URL %s' % self .url )
136139 self .url = 'http://' + self .url
137140
138141 def is_enabled (self , spider ):
@@ -216,7 +219,7 @@ def process_response(self, request, response, spider):
216219 return self ._retry_auth (response , request , spider )
217220 else :
218221 self .crawler .stats .inc_value ('zyte_smartproxy/retries/auth/max_reached' )
219- logging .warning (
222+ logger .warning (
220223 "Max retries for authentication issues reached, please check auth"
221224 " information settings" ,
222225 extra = {'spider' : self .spider },
@@ -263,7 +266,7 @@ def _handle_not_enabled_response(self, request, response):
263266 return response
264267
265268 def _retry_auth (self , response , request , spider ):
266- logging .warning (
269+ logger .warning (
267270 "Retrying a Zyte Smart Proxy Manager request due to an "
268271 "authentication issue" ,
269272 extra = {'spider' : self .spider },
@@ -357,7 +360,7 @@ def _set_zyte_smartproxy_default_headers(self, request):
357360 'urls with problems.'
358361 % str (self .conflicting_headers )
359362 )
360- logging .debug (
363+ logger .debug (
361364 'The headers %s are conflicting on request %s. X-Crawlera-UA '
362365 'will be ignored. Please check '
363366 'https://docs.zyte.com/smart-proxy-manager.html#request-headers '
0 commit comments