hgducharme / lichess-bot

A middle-man between your chess engine and lichess.com
GNU General Public License v3.0
1 stars 0 forks source link

Implement a way to check if lichess accidentally closed a connection. If they did then try to restart the connection and resend the command #4

Open hgducharme opened 2 years ago

hgducharme commented 1 year ago

Maybe all get and post commands can be wrapped in a try and except block? We can catch a ConnectionError and handle it accordingly.

hgducharme commented 1 year ago

What happens if the EventStreamWatcher loses connection while streaming the events? Here's a reference to get started:

https://stackoverflow.com/questions/25860105/python-requests-package-lost-connection-while-streaming

hgducharme commented 1 year ago

https://stackoverflow.com/questions/49694126/python-3-requests-library-iter-lines-handling-possible-server-stalls-when

hgducharme commented 1 year ago

Maybe upon when we establish a Session we can save the session ID or some unique identifier to pass to lichess.com later if the connection is closed, so that we can resume with the same session data as before

hgducharme commented 1 year ago

Got this exception when attempting to send a challenge

Exception has occurred: ConnectionError
('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
TypeError: getresponse() got an unexpected keyword argument 'buffering'

During handling of the above exception, another exception occurred:

  File "<string>", line 3, in raise_from
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

  File "<string>", line 3, in raise_from
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

  File "/Users/hgd/repos/chessAI/src/lichess/LichessAPI.py", line 88, in create_challenge
    response = self.session.post(url, data = request_body)
  File "/Users/hgd/repos/chessAI/src/lichess/ChallengeStreamWatcher.py", line 38, in _send_user_challenge
    response = self.api.create_challenge(username, settings.CHALLENGE_PARAMS["real_time"])
  File "/Users/hgd/repos/chessAI/src/lichess/ChallengeStreamWatcher.py", line 23, in work
    self._send_user_challenge()
  File "/Users/hgd/repos/chessAI/src/lichess/ContinuousThread.py", line 19, in run
    self.work()
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))