import requests
import requests_ftp
-from Robots.bkmk_robot_base import robot_base
+from Robots.bkmk_robot_base import robot_base, request_headers
requests_ftp.monkeypatch_session()
if url_host in self.proxy_error:
return 'proxy error', None, None, None, None
+ if accept_charset and bookmark.charset:
+ headers = request_headers.copy()
+ headers['Accept-Charset'] = bookmark.charset
+ else:
+ headers = request_headers
+
if url_host in self.proxy_ok:
self.log(' Immediately trying with the proxy')
- error, r = request_get(url, self.timeout, self.proxy)
+ error, r = request_get(url, headers, self.timeout, self.proxy)
else:
- error, r = request_get(url, self.timeout, None)
+ error, r = request_get(url, headers, self.timeout, None)
if error is not None:
self.log(' Error: %s' % error)
if self.proxy:
self.log(' Retrying with the proxy...')
- error, r = request_get(url, self.timeout, self.proxy)
+ error, r = request_get(url, headers,
+ self.timeout, self.proxy)
if error is None:
self.proxy_ok.add(url_host)
if error is not None:
return '' # Alas, requests_ftp doesn't store welcome message
-def request_get(url, timeout, proxy):
+def request_get(url, headers, timeout, proxy):
if proxy:
proxies = {'http': proxy, 'https': proxy}
else:
try:
r = requests.Session().get(
- url, timeout=timeout, allow_redirects=False, proxies=proxies)
+ url, headers=headers, timeout=timeout,
+ allow_redirects=False, proxies=proxies)
except requests.RequestException as e:
return str(e), None
else: