box / box-python-sdk

Box SDK for Python
http://opensource.box.com/box-python-sdk/
Apache License 2.0
418 stars 215 forks source link

ConnectionResetError(10054) when I get some information about the contents. #757

Closed c-rei closed 1 year ago

c-rei commented 2 years ago

I want to get some information of my contents, so I do tow steps like below.

1 step: I got a contents list, and output them to csv file with item name, id, and type. I used "items = folder.get_items()", and with recursion route, I can got 40,000 items.

2 step: I want to get the collaborations and shared links using "item.get_collaborations()" and "item.shared_link" through my csv file that got on step one.

After about 2 hours, I got the error like that "'Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)". So I can't complete my process.

I want to known what's wrong with my process. How can I avoid this error.

Versions Used

Python SDK: 3.2.0 Python: 3.8.8 and my csv file. csv

mwwoda commented 2 years ago

Hi @c-rei Can you provide a sample of the code you are trying to run? Does this problem occur consistently after 2 hours or only sometimes?

Please make sure your environment (e.g. network, proxy configuration) is not interfering with the code you are trying to run. You can also try increasing the number of retries and see if that helps. - https://github.com/box/box-python-sdk/blob/main/docs/usage/configuration.md#max-retry-attmepts

c-rei commented 2 years ago

Hi sir This problem occurs after 2 hours and sometimes, even immediately after execution. My code samples like this, err1 err2

c-rei commented 2 years ago

And I have another problem, it occurs after long run with same code. (no proxy environment)

('Connection aborted.', TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None))

mwwoda commented 2 years ago

So looking at the errors you are getting, the fact that the problem is non-deterministic and after talking with other team members I think that it is most likely a client or server problem. I don't see much impact the sdk can have. There are a few steps you can take to try to solve your issue:

  1. Troubleshoot the network connection further. You may get some of these errors because, for example, you lost your connection while executing code. Make also sure that your e.g. firewall is not blocking any outgoing/outgoing requests. Make sure that your environment is not causing these issues.
  2. If increasing the number of retry attempts doesn't help, you can try wrapping api calls in a try/except clause. In the except block, you can try to establish a new connection to the box api. This could help if there is some problem with existing connection.
  3. If you are still encountering the problem and you think it's server-side problem, I would advise you to contact our backend team. You can create a ticket at https://support.box.com/hc/en-us/requests/new so that they can investigate it further.
c-rei commented 2 years ago

Thanks your advise. But I'm not sure your "wrapping api calls" means. To try wrapping api calls in a try/except clause, I want to do like a sample below? num = 0 while True: try: a_folder = client.folder(folder_id="123456789").get() break except requests.RequestException: if num < 5: num += 1 continue else: raise except Exception: raise