@Julio_Ernandes

Из за чего возникает ошибка Max retries exceeded with url от Selenium Python?

Здравствуйте, когда запускал софт в один поток на 10-15 ссылок все было хорошо, но когда захотел добавить многопроцессорность столкнулся с проблемой.

Как и на гайдах импортирую объект Pool после чего даю ему процесс равным например двум.
Открывается сразу 5 браузеров, при этом софт в первых двух браузерах открывает ссылки но когда дело доходит до 3 - 4 браузеров вылетает ошибка и они закрываются, но 5 браузер почему то просто висит

code
def regist(url_line):
    body_dict, submit_btn, agree_btn, url, inputs, opener = parse_line(url_line)
    function_start_count = 0
    driver.get(url)
    print(Back.BLACK + Fore.BLUE + f'Перешли нa: {url}')
    if opener:
        opener = temp_button(body_dict['opener'], function_start_count)
        function_start_count += 1
        time.sleep(2)

    input_first = temp_button(body_dict['first_select'], function_start_count)
    function_start_count += 1


    for i in range(len(inputs)):
        if i == 0:
            input_first.send_keys(man_full[inputs[i].lower()])
        else:
            input_first.send_keys((Keys.TAB,)*(i), man_full[inputs[i].lower()])
        time.sleep(1)

    if agree_btn:
        agree_btn = temp_button(body_dict['agree'], function_start_count)
        function_start_count += 1
    time.sleep(1)
    if submit_btn:
        submit_btn = temp_button(body_dict['submit'], function_start_count)
        function_start_count += 1
        # scroll()
    else:
        input_first.send_keys(Keys.ENTER)
    time.sleep(3)
    driver.delete_all_cookies()


def get_data(url_line):
    try:
        print('начали')
        regist(url_line)
    except Exception as ex:
        print(ex)
    finally:
        driver.close()
        driver.quit()
if __name__ == '__main__':
    p = Pool(processes=2)
    p.map(get_data, url_list)


traceback
multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\util\connection.py", line 95, in create_connection
    raise err
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061] Подключение не установлено, т.к. конечный компьютер отверг запрос на подключение

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\connection.py", line 244, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 1283, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 1329, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 1278, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 1038, in _send_output
    self.send(msg)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 976, in send
    self.connect()
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\connection.py", line 205, in connect
    conn = self._new_conn()
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x000002907CC97100>: Failed to establish a new connection: [WinError 10061] Подключение не установлено, т.к. конечный компьютер отверг запрос на подключение

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\multiprocessing\pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\multiprocessing\pool.py", line 48, in mapstar
    return list(map(*args))
  File "C:\Users\myuser\Desktop\reg-pyhton\back.py", line 161, in get_data
    regist(url_line)
  File "C:\Users\myuser\Desktop\reg-pyhton\back.py", line 119, in regist
    driver.get(url)
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 449, in get
    self.execute(Command.GET, {"url": url})
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 438, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 290, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 311, in _request
    response = self._conn.request(method, url, body=body, headers=headers)
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\request.py", line 78, in request
    return self.request_encode_body(
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\request.py", line 170, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\poolmanager.py", line 376, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\connectionpool.py", line 815, in urlopen
    return self.urlopen(
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\connectionpool.py", line 815, in urlopen
    return self.urlopen(
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\connectionpool.py", line 815, in urlopen
    return self.urlopen(
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "C:\Users\myuser\Desktop\reg-pyhton\venv\lib\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=61999): Max retries exceeded with url: /session/9948d9a12a1fa319c8166c8aa13f8885/url (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000002907CC97100>: Failed to establish a new connection: [WinError 10061] Подключение не установлено, т.к. конечный компьютер отверг запрос на подключение'))
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\myuser\Desktop\reg-pyhton\back.py", line 167, in <module>
    p.map(get_data, url_list)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\multiprocessing\pool.py", line 367, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\multiprocessing\pool.py", line 774, in get
    raise self._value
urllib3.exceptions.MaxRetryError: None: Max retries exceeded with url: /session/9948d9a12a1fa319c8166c8aa13f8885/url (Caused by None)

Process finished with exit code 1


более краткая версия ошибки
HTTPConnectionPool(host='localhost', port=57041): Max retries exceeded with url: /session/650872231b1b618eba0722937d87a239/url (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001235EFA6800>: Failed to establish a new connection: [WinError 10061] Подключение не установлено, т.к. конечный компьютер отверг запрос на подключение'))


Я новичок в python и возможно еще не все понимаю, поэтому буду крайне признателен. Заранее спасибо!
  • Вопрос задан
  • 1034 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы
22 нояб. 2024, в 12:20
10000 руб./за проект
22 нояб. 2024, в 11:53
3000 руб./за проект
22 нояб. 2024, в 11:51
20000 руб./за проект