1 """Robot based on requests
3 This file is a part of Bookmarks database and Internet robot.
7 __author__ = "Oleg Broytman <phd@phdru.name>"
8 __copyright__ = "Copyright (C) 2024, 2025 PhiloSoft Design"
9 __license__ = "GNU GPL"
11 __all__ = ['robot_requests']
16 from requests.adapters import HTTPAdapter
17 from requests.packages.urllib3.util.ssl_ import create_urllib3_context
21 from Robots.base import robot_base
22 from Robots.util import get_ftp
25 class robot_requests(robot_base):
26 def version_str(self):
27 return 'python-requests urllib3/%s' % urllib3.__version__
29 async def get(self, url, req_headers, use_proxy=False):
30 if url.startswith('ftp://'):
31 error, welcome, body = get_ftp(url, self.timeout)
33 return error, None, None, None
34 self.welcome = welcome
35 return None, None, None, body
38 proxies = {'http': self.proxy, 'https': self.proxy}
42 s = requests.Session()
43 s.mount('https://', AllCiphersAdapter())
47 r = s.get(url, headers=req_headers, timeout=self.timeout,
48 allow_redirects=False, proxies=proxies,
50 except requests.RequestException as e:
52 return error, None, None, None
54 return None, r.status_code, r.headers, r.content
56 def get_ftp_welcome(self):
57 welcome = self.welcome
62 # See https://lukasa.co.uk/2017/02/Configuring_TLS_With_Requests/
64 class AllCiphersAdapter(HTTPAdapter):
66 A TransportAdapter that re-enables 3DES support in Requests.
68 def init_poolmanager(self, *args, **kwargs):
69 context = create_urllib3_context(cert_reqs=0,
70 ciphers='ALL:@SECLEVEL=1')
71 kwargs['ssl_context'] = context
72 return super(AllCiphersAdapter, self).init_poolmanager(*args, **kwargs)
74 def proxy_manager_for(self, *args, **kwargs):
75 context = create_urllib3_context(cert_reqs=0,
76 ciphers='ALL:@SECLEVEL=1')
77 kwargs['ssl_context'] = context
78 return super(AllCiphersAdapter, self).proxy_manager_for(
82 warnings.filterwarnings('ignore', 'Unverified HTTPS request is being made')