Python Forum
Backconnect proxy, response timeout
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Backconnect proxy, response timeout
#1
Good afternoon. The problem is not very complicated, but I can not find a solution.

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')))"))]
Reply
#2
Problem solved!!

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))
  
  
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'))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  telnetlib timeout kerzol81 0 3,412 Sep-12-2019, 08:38 AM
Last Post: kerzol81

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020