BattleOfAI
BattleOfAI copied to clipboard
"Max retries exceeded with url"-error when using handle_available()
The API crashes about every 5 minutes when using the code below.
def turn(board, symbol):
# some code
return x, y
api = BOAIapi(turn, verbose=1)
while True:
api.handle_available()
time.sleep(5)
The stacktrace:
Fri 13:17:57 [BOAIapi] handle_available: Done handling available
Fri 13:18:02 [BOAIapi] handle_available: Handled 170 (Not your turn)
Fri 13:18:02 [BOAIapi] handle_available: Handled 171 (Not your turn)
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connection.py", line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\util\connection.py", line 83, in create_connection
raise err
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\util\connection.py", line 73, in create_connection
sock.connect(sa)
OSError: [WinError 10013] Der Zugriff auf einen Socket war aufgrund der Zugriffsrechte des Sockets unzulässig
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
chunked=chunked)
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 346, in _make_request
self._validate_conn(conn)
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 850, in _validate_conn
conn.connect()
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connection.py", line 284, in connect
conn = self._new_conn()
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connection.py", line 150, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x000001AF6ABA8320>: Failed to establish a new connection: [WinError 10013] Der Zugriff auf einen Socket war aufgrund der Zugriffsrechte des Sockets unzulässig
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 440, in send
timeout=timeout
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\util\retry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='games.battleofai.net', port=443): Max retries exceeded with url: /api/games/172 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000001AF6ABA8320>: Failed to establish a new connection: [WinError 10013] Der Zugriff auf einen Socket war aufgrund der Zugriffsrechte des Sockets unzulässig',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "PlayOnline.py", line 28, in <module>
api.handle_available()
File "X:\CoRe-AI\BOAIapi.py", line 212, in handle_available
game_status = self.status(game_id)
File "X:\CoRe-AI\BOAIapi.py", line 129, in status
return requests.get(self.games_api_url + "games/" + str(game_id)).json()
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 508, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='games.battleofai.net', port=443): Max retries exceeded with url: /api/games/172 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000001AF6ABA8320>: Failed to establish a new connection: [WinError 10013] Der Zugriff auf einen Socket war aufgrund der Zugriffsrechte des Sockets unzulässig',))
My Solution
Since I did not find any piece of code in the backend that would trigger such behavior, I assume that the problem is on the client side (caused eg by short disconnects at an unfavorable time) or directly on the server. On the client side, I couldn't find anything better than a try / except for this problem, which I have implemented for me and it works great so far. On the server side, I have absolutely no plan and can't do anything anyway.
If no one else encounters this problem i assume that it was a local problem and can be resolved by the steps described above.