Jul-14-2023, 04:11 PM
(This post was last modified: Jul-14-2023, 04:11 PM by 3frenky3.
Edit Reason: change text
)
Good afternoon. The problem is not very complicated, but I can not find a solution.
How can I put a limiter on waiting for a response? I've already tried everything.
With socks5 everything works as it should.
after 5 min i have rror:
ProxyError(MaxRetryError("HTTPSConnectionPool(host='https://my-site.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', timeout('timed out')))"))]
def main_request(data, proxy='', type_of_proxy='socks5', user_agent='Mozilla/5.0 (Linux; arm; Android 13; PEPM00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.141 YaBrowser/22.3.6.61.00 SA/3 Mobile Safari/537.36'): class TimeoutHTTPAdapter(HTTPAdapter): def __init__(self, *args, **kwargs): if "timeout" in kwargs: self.timeout = kwargs["timeout"] del kwargs["timeout"] super().__init__(*args, **kwargs) def send(self, request, **kwargs): timeout = kwargs.get("timeout") if timeout is None and hasattr(self, 'timeout'): kwargs["timeout"] = self.timeout return super().send(request, **kwargs) s = requests.Session() s.mount('http://', TimeoutHTTPAdapter(timeout=5)) # 5 seconds s.mount('https://', TimeoutHTTPAdapter(timeout=5)) retry = Retry(connect=3, backoff_factor=0.7) adapter = HTTPAdapter(max_retries=retry) s.mount('http://', adapter) s.mount('https://', adapter) if type_of_proxy == 'socks5': timeout_request = 3 elif type_of_proxy == 'http': timeout_request = 1 proxies = { 'http': f'{type_of_proxy}://{proxy}', 'https': f'{type_of_proxy}://{proxy}' } page_login = s.post('https://my-site.com', data=data_1.encode('utf-8'), verify=False, proxies=proxies, headers=headers_dic,timeout=timeout_request) print(main_request(data='1',proxy='login:[email protected]:16000',type_of_proxy='http'))The problem is that when there is a request, I wait for a response from 10 to 120 seconds. Sometimes it comes in the first 3 seconds.
How can I put a limiter on waiting for a response? I've already tried everything.
With socks5 everything works as it should.
after 5 min i have rror:
ProxyError(MaxRetryError("HTTPSConnectionPool(host='https://my-site.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', timeout('timed out')))"))]