class robot_requests(robot_base):
+ # Pass proxy from the environment like this:
+ # BKMK_ROBOT=requests:proxy=socks5h%3a//localhost%3a1080
+ proxy = None
+
def get(self, bookmark, url, accept_charset=False):
try:
r = requests.Session().get(
except requests.RequestException as e:
error = str(e)
self.log(' Error: %s' % error)
- return error, None, None, None, None
- else:
- if r.is_redirect:
- return None, r.status_code, r.next.url, None, None
- return None, None, None, r.headers, r.content
+ if self.proxy:
+ error = None
+ self.log(' Retrying with the proxy...')
+ try:
+ r = requests.get(
+ url, timeout=self.timeout, allow_redirects=False,
+ proxies={'http': self.proxy, 'https': self.proxy})
+ except requests.RequestException as e:
+ error = str(e)
+ self.log(' Proxy error: %s' % error)
+ if error is not None:
+ return error, None, None, None, None
+ if r.is_redirect:
+ return None, r.status_code, r.next.url, None, None
+ return None, None, None, r.headers, r.content
def get_ftp_welcome(self):
return '' # Alas, requests_ftp doesn't store welcome message
]
-from urllib.parse import urlsplit, quote
+from urllib.parse import urlsplit, quote, unquote
import os
BKMK_FORMAT = os.environ.get("BKMK_FORMAT", "MOZILLA")
param_list = {}
for param in params:
key, value = param.split('=', 1)
- param_list[key] = value
+ param_list[key] = unquote(value)
return main_param, param_list