Maximum of api retries exceeded вк ошибка авторизации

Ожидают ответа 1 человек. Станьте первым, кто даст ответ! Или подпишитесь на вопрос, чтобы узнать ответ, когда он появится.

Сталкиваюсь не первый раз с этой проблемой, закрывал глаза, но сейчас хочу решить эту проблему.
При старте бота изредка выскакивает ошибка, или в работе бота. Выдает ошибку и на vds и на локалке.

Traceback (most recent call last):
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesurllib3connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesurllib3utilconnection.py", line 57, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsocket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11002] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesurllib3connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesurllib3connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesurllib3connectionpool.py", line 839, in _validate_conn
    conn.connect()
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesurllib3connection.py", line 301, in connect
    conn = self._new_conn()
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesurllib3connection.py", line 168, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x04EAD110>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesrequestsadapters.py", line 449, in send
    timeout=timeout
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesurllib3connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesurllib3utilretry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.vk.com', port=443): Max retries exceeded with url: /method/stats.trackVisitor (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x04EAD110>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Bogdan/PycharmProjects/?/---.py", line 1, in <module>
    from --- import *
  File "C:UsersBogdanPycharmProjects?---.py", line 24, in <module>
    from --- import *
  File "C:UsersBogdanPycharmProjects?---.py", line 122, in <module>
    vk._auth_token()
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesvk_apivk_api.py", line 209, in _auth_token
    if not reauth and self._check_token():
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesvk_apivk_api.py", line 501, in _check_token
    self.method('stats.trackVisitor')
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesvk_apivk_api.py", line 602, in method
    values
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesrequestssessions.py", line 581, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesrequestssessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesrequestssessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:UsersBogdanAppDataLocalProgramsPythonPython37-32libsite-packagesrequestsadapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.vk.com', port=443): Max retries exceeded with url: /method/stats.trackVisitor (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x04EAD110>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))

точно такая же ошибка при использовании валидных прокси.
vk_session.http.proxies ={ 'http': 'http://user:password@proxyip:port, 'https': 'http://user:password@proxyip:port' }
причем все обычные запросы апи работают отлично в том числе и messages (app_id spoof). но вот VkLongPool бросает ошибку как у ТС

requests.exceptions.ProxyError: HTTPSConnectionPool(host='api.vk.com', port=443): Max retries exceeded with url: /method/messages.getLongPollServer (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))
большая просьба сделать фикс или подсказать, где косячу

  File "/Users/mac1/PycharmProjects/TestVkApi/VkApiMain.py", line 95, in <module>
    main()
  File "/Users/mac1/PycharmProjects/TestVkApi/VkApiMain.py", line 55, in main
    for event in longpoll.listen():
  File "/Users/mac1/PycharmProjects/TestVkApi/venv/lib/python3.7/site-packages/vk_api/longpoll.py", line 621, in listen
    for event in self.check():
  File "/Users/mac1/PycharmProjects/TestVkApi/venv/lib/python3.7/site-packages/vk_api/longpoll.py", line 582, in check
    self.update_longpoll_server(update_ts=False)
  File "/Users/mac1/PycharmProjects/TestVkApi/venv/lib/python3.7/site-packages/vk_api/longpoll.py", line 531, in update_longpoll_server
    response = self.vk.method('messages.getLongPollServer', values)
  File "/Users/mac1/PycharmProjects/TestVkApi/venv/lib/python3.7/site-packages/vk_api/vk_api.py", line 612, in method
    values
  File "/Users/mac1/PycharmProjects/TestVkApi/venv/lib/python3.7/site-packages/requests/sessions.py", line 578, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/Users/mac1/PycharmProjects/TestVkApi/venv/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/mac1/PycharmProjects/TestVkApi/venv/lib/python3.7/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/Users/mac1/PycharmProjects/TestVkApi/venv/lib/python3.7/site-packages/requests/adapters.py", line 510, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='api.vk.com', port=443): Max retries exceeded with url: /method/messages.getLongPollServer (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Traceback (most recent call last):
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsite-packagesurllib3utilconnection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsocket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11004] getaddrinfo failed
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connectionpool.py", line 346, in _make_request
    self._validate_conn(conn)
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connectionpool.py", line 850, in _validate_conn
    conn.connect()
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connection.py", line 284, in connect
    conn = self._new_conn()
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connection.py", line 150, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x02DFE190>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsite-packagesrequestsadapters.py", line 440, in send
    timeout=timeout
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsite-packagesurllib3utilretry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.vk.com', port=443): Max retries exceeded with url: /method/users.get?user_id=210700286&v=5.52 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x02DFE190>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed',))
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
  File "C:/Users/_aaa_/AppData/Local/Programs/Python/Python36-32/Vk9.py", line 3, in <module>
    response = requests.get("https://api.vk.com/method/users.get?user_id=210700286&v=5.52")
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsite-packagesrequestsapi.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsite-packagesrequestsapi.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsite-packagesrequestssessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsite-packagesrequestssessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "C:Users_aaa_AppDataLocalProgramsPythonPython36-32libsite-packagesrequestsadapters.py", line 508, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.vk.com', port=443): Max retries exceeded with url: /method/users.get?user_id=210700286&v=5.52 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x02DFE190>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed',))

Проблемы с SSL при использовании VK API

При реализации одного из проектов, связанных с API VK я столкнулся с одной крайне интересной проблемой. У меня просто перестал работать скрипт, при этом выдавая следующую ошибку:


Traceback (most recent call last):
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3contribpyopenssl.py", line 441, in wrap_socket
    cnx.do_handshake()
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesOpenSSLSSL.py", line 1806, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesOpenSSLSSL.py", line 1546, in _raise_ssl_error
    _raise_current_error()
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesOpenSSL_util.py", line 54, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connectionpool.py", line 346, in _make_request
    self._validate_conn(conn)
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connectionpool.py", line 850, in _validate_conn
    conn.connect()
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connection.py", line 326, in connect
    ssl_context=context)
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3utilssl_.py", line 329, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3contribpyopenssl.py", line 448, in wrap_socket
    raise ssl.SSLError('bad handshake: %r' % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesrequestsadapters.py", line 440, in send
    timeout=timeout
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3utilretry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='m.vk.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
  File "E:workpythonvkparse_group.py", line 5, in <module>
    session = vk.AuthSession(app_id='***', user_login='***', user_password='***')
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesvkmixins.py", line 32, in __init__
    self.access_token = self.get_access_token()
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesvkmixins.py", line 69, in get_access_token
    self.login()
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesvkmixins.py", line 82, in login
    response = self.auth_session.get(self.LOGIN_URL)
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesrequestssessions.py", line 521, in get
    return self.request('GET', url, **kwargs)
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesvkutils.py", line 78, in request
    response = super(LoggingSession, self).request(method, url, **kwargs)
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesrequestssessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesrequestssessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesrequestsadapters.py", line 506, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='m.vk.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
 
 

Странность состояла в том, что на двух виндовых машинах данный скрипт не запускался, а на unix машине все работало без проблем. Искал долго решение проблемы, но ни к чему это не привело. Как итог я сделал следующий костыль:


Отключил проверку сертификата в файле utils.py (Libsite-packagesvk)

# Строка 78
response = super(LoggingSession, self).request(method, url, **kwargs, verify=False)




После этого все заработало, но начали появляться предупреждения типа

C:UsersOlegAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

Которые убрались внедрением следующего кода:


import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

Я понимаю, что это достаточно кривой способ решения проблемы, но пока я даже причины не нашел, поэтому приходится довольствоваться подобными “костылями”.

Python is a simple, minimalistic, and easy-to-comprehend programming language that is globally-accepted and universally-used today. Its simple, easy-to-learn syntax can sometimes lead Python developers – especially those who are newer to the language – into missing some of its subtleties and underestimating the power of the diverse Python language.

One of the most popular error messages that new developers encounter when using requests library in Python is the “Max retries exceeded with URL” (besides timeout errors). While it seems simple, sometimes this somewhat vague error message can make even advanced Python developers scratching their head for a few good hours.

This article will show you what causes “Max retries exceeded with URL” error and a few ways to debug it.

Max retries exceeded with URL is a common error, you will encounter it when using requests library to make a request. The error indicates that the request cannot be made successfully. Usually, the verbose error message should look like the output below

Traceback (most recent call last): File "/home/nl/example.py", line 17, in <module> page1 = requests.get(ap) File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 55, in get return request('get', url, **kwargs) File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 44, in request return session.request(method=method, url=url, **kwargs) File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 383, in request resp = self.send(prep, **send_kwargs) File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 486, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 378, in send raise ConnectionError(e) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='localhost.com', port=443): Max retries exceeded with url: /api (Caused by <class 'socket.gaierror'>: [Errno -2] Name or service not known)

Code language: JavaScript (javascript)

Sometimes, the error message may look slightly different, like below :

requests.exceptions.ConnectionError(MaxRetryError("HTTPSConnectionPool(host='api.example.com', port=443): Max retries exceeded with url: /api.json ( Caused by <class 'socket.error'>: [Errno 10054] An existing connection was forcibly closed by the remote host)",),)

Code language: HTML, XML (xml)

requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8001): Max retries exceeded with url: /api (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10f96ecc0>: Failed to establish a new connection: [Errno 61] Connection refused'))

Code language: JavaScript (javascript)

requests.exceptions.ConnectionError: HTTPConnectionPool(host='www.example.com', port=80): Max retries exceeded with url: /api (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000008EC69AAA90>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

Code language: JavaScript (javascript)

requests.exceptions.SSLError: HTTPSConnectionPool(host='example.com', port=443): Max retries exceeded with url: /api (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:997)')))

Code language: JavaScript (javascript)

The error message usually begins with requests.exceptions.ConnectionError, which tell us that there is something bad happened when requests was trying to connect. Sometimes, the exception is requests.exceptions.SSLError which is obviously a SSL-related problem.

The exception then followed by a more detailed string about the error, which could be Failed to establish a new connection: [Errno 61] Connection refused, [Errno 11001] getaddrinfo failed, [Errno 10054] An existing connection was forcibly closed by the remote host or [Errno -2] Name or service not known. These messages were produced by the underlying system library which requests called internally. Based on these texts, we can further isolate and fix the problems.

Double-check the URL

There are a possibility that your requested URL wrong. It may be malformed or leading to a non-existent endpoint. In reality, this is usually the case among Python beginners. Seasoned developers can also encounter this error, especially when the URL is parsed from a webpage, which can be a relative URL or schemeless URL.

One way to further debug this is to prepare the URL in advance, then print it before actually making a connection.

# ... url = soup.find("#linkout").href print(url) # prints out "/api" which is a non-valid URL r = requests.get(url)

Code language: PHP (php)

Unstable internet connection / server overload

The underlying problem may be related to your own connection or the server you’re trying to connect to. Unstable internet connection may cause packet loss between network hops, leading to unsuccessful connection. There are times the server has received so many requests that it cannot process them all, therefore your requests won’t receive a response.

In this case, you can try increasing retry attempts and disable keep-alive connections to see if the problems go away. The amount of time spent for each request will certainly increase too, but that’s a trade-off you must accept. Better yet, find a more reliable internet connection.

import requests requests.adapters.DEFAULT_RETRIES = 5 # increase retries number s = requests.session() s.keep_alive = False # disable keep alive s.get(url)

Code language: PHP (php)

Increase request timeout

Another way that you can avoid “Max retries exceeded with URL” error, especially when the server is busy handling a huge number of connections, is to increase the amount of time requests library waits for a response from the server. In other words, you wait longer for a response, but increase the chance for a request to successfully finishes. This method can also be applied when the server is in a location far away from yours.

In order to increase request timeout, simply pass the time value in seconds to the get or post method :

r = requests.get(url, timeout=3)

You can also pass a tuple to timeout with the first element being a connect timeout (the time it allows for the client to establish a connection to the server), and the second being a read timeout (the time it will wait on a response once your client has established a connection).

If the request establishes a connection within 2 seconds and receives data within 5 seconds of the connection being established, then the response will be returned as it was before. If the request times out, then the function will raise a Timeout exception:

requests.get('https://api.github.com', timeout=(2, 5))

Code language: JavaScript (javascript)

Apply backoff factor

backoff_factor is an urllib3 argument, the library which requests relies on to initialize a network connection. Below is an example where we use backoff_factor to slow down the requests to the servers whenever there’s a failed one.

import requests from requests.adapters import HTTPAdapter from requests.packages.urllib3.util.retry import Retry session = requests.Session() retry = Retry(connect=3, backoff_factor=1) adapter = HTTPAdapter(max_retries=retry) session.mount('http://', adapter) session.mount('https://', adapter) session.get(url)

Code language: JavaScript (javascript)

According to urllib3 documentation, backoff_factor is base value which the library use to calculate sleep interval between retries. Specifically, urllib3 will sleep for {backoff factor} * (2 ^ ({number of total retries} - 1)) seconds after every failed connection attempt.

For example, If the backoff_factor is 0.1, then sleep() will sleep for 0.0s, 0.2s, 0.4s, … between retries. By default, backoff is disabled (set to 0). It will also force a retry if the status code returned is 500, 502, 503 or 504.

You can customize Retry to have even more granular control over retries. Other notable options are:

  • total – Total number of retries to allow.
  • connect – How many connection-related errors to retry on.
  • read – How many times to retry on read errors.
  • redirect – How many redirects to perform.
  • _methodwhitelist – Set of uppercased HTTP method verbs that we should retry on.
  • _statusforcelist – A set of HTTP status codes that we should force a retry on.
  • _backofffactor – A backoff factor to apply between attempts.
  • _raise_onredirect – Whether, if the number of redirects is exhausted, to raise a MaxRetryError, or to return a response with a response code in the 3xx range.
  • raise_on_status – Similar meaning to _raise_onredirect: whether we should raise an exception, or return a response, if status falls in _statusforcelist range and retries have been exhausted.

We hope that the article helped you successfully debugged “Max retries exceeded with URL” error in Python requests library, as well as avoid encountering it in the future. We’ve also written a few other guides for fixing common Python errors, such as Timeout in Python requests, Python Unresolved Import in VSCode or “IndexError: List Index Out of Range” in Python. If you have any suggestion, please feel free to leave a comment below.

Понравилась статья? Поделить с друзьями:
  • Maximum call stack size exceeded как исправить react
  • Maximum call stack size exceeded как исправить google chrome
  • Max payne ошибка jpeg error
  • Max payne runtime error
  • Max payne an error has occurred in the graphics engine