inventree / inventree-python

Python library for communication with inventree via API
https://docs.inventree.org/en/latest/api/python/python/
MIT License
27 stars 35 forks source link

How to keep a connection with InvenTree open #242

Open realstudent01 opened 2 months ago

realstudent01 commented 2 months ago

I am making a front end dashboard to view some information in a database with the InvenTree API. Seemingly randomly I am getting the following errors:

"requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))"

"requests.exceptions.ChunkedEncodingError: ("Connection broken: ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)", ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))"

Is the issue that I need to do something to keep the api instance (that I initialize to make the connection) open? Or do I need to give a certain value as the timeout?

SchrodingersGat commented 2 months ago

You should not assume that the connection attempt will always work - there can be timeouts, other interrupts, etc. I would wrap your code in a try / except block, and handle any failures accordingly. Probably just by re-attempting.

Adding a small delay between requests will probably help, too.