ppf: add safeguards against tor outage
This commit is contained in:
24
ppf.py
24
ppf.py
@@ -43,11 +43,25 @@ def fetch_contents(url):
|
|||||||
'Accept-Language: en-US,en;q=0.8',
|
'Accept-Language: en-US,en;q=0.8',
|
||||||
'Cache-Control: max-age=0',
|
'Cache-Control: max-age=0',
|
||||||
]
|
]
|
||||||
proxies = [rocksock.RocksockProxyFromURL('socks4://%s' % random.choice( config.torhosts ))]
|
while True:
|
||||||
http = RsHttp(host,ssl=ssl,port=port, keep_alive=True, timeout=config.ppf.timeout, max_tries=config.ppf.http_retries, follow_redirects=True, auto_set_cookies=True, proxies=proxies, user_agent='Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0')
|
proxies = [rocksock.RocksockProxyFromURL('socks4://%s' % random.choice( config.torhosts ))]
|
||||||
if not http.connect():
|
http = RsHttp(host,ssl=ssl,port=port, keep_alive=True, timeout=config.ppf.timeout, max_tries=config.ppf.http_retries, follow_redirects=True, auto_set_cookies=True, proxies=proxies, user_agent='Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0')
|
||||||
_log("failed to connect to %s"%url, "ppf")
|
if not http.connect():
|
||||||
return ''
|
_log("failed to connect to %s"%url, "ppf")
|
||||||
|
e = http.get_last_rocksock_exception()
|
||||||
|
if not e:
|
||||||
|
return ''
|
||||||
|
et = e.get_errortype()
|
||||||
|
ee = e.get_error()
|
||||||
|
ef = e.get_failedproxy()
|
||||||
|
if et == rocksock.RS_ET_OWN and \
|
||||||
|
ee == rocksock.RS_E_TARGET_CONN_REFUSED \
|
||||||
|
and ef == 0:
|
||||||
|
_log("could not connect to proxy 0 - check your connection", "error")
|
||||||
|
time.sleep(5)
|
||||||
|
continue
|
||||||
|
return ''
|
||||||
|
break
|
||||||
hdr, res = http.get(uri, headers)
|
hdr, res = http.get(uri, headers)
|
||||||
res = res.encode('utf-8') if isinstance(res, unicode) else res
|
res = res.encode('utf-8') if isinstance(res, unicode) else res
|
||||||
for retry_message in retry_messages:
|
for retry_message in retry_messages:
|
||||||
|
|||||||
Reference in New Issue
Block a user