You need to connect to the site through a randomly selected proxy server from the list. The list is loaded from file. In principle, everything works, but there is one thing. Namely: the connection through the proxy hangs up and the program cannot end. The timeouts and try/except are set correctly, but this does not save. How to be?

 import requests import random import logging logging.basicConfig(level=logging.DEBUG) with open('\\proxy.txt' , 'r', encoding = 'utf-8') as proxy_file: proxy_lines = proxy_file.readlines() ii = 1 while ii < 1000: proxy_line = proxy_lines[random.randint(1, len(proxy_lines)-1)].strip() session = requests.session() session.temeout = (3) Adapter = requests.adapters.HTTPAdapter(pool_connections = 1, pool_maxsize = 0, max_retries = 0) session.mount('http://', Adapter) session.mount('https://', Adapter) session.proxies = { 'http' : proxy_line, 'https' : proxy_line } try: request = session.post('https://www.site.com/') print('Подключение удалось | ' + proxy_line) request.close except Exception as exception: #print(exception) print('Подключение не удалось. Переподключение. ' + proxy_line) ii = ii + 1 

    1 answer 1

    Perhaps you made a mistake, Session does not have the session.temeout attribute and session.timeout too.
    You need to set the timeout parameter when calling post :
    request = session.post('https://www.site.com/', timeout=3)

    Object documentation Session: requests.Session