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

Chunk upload always fails with SSLError #766

Closed SakethValiveti closed 1 year ago

SakethValiveti commented 1 year ago

Description of the Issue

I'm trying to consistently upload large files (10-50GB) using the chunked uploader process. During code execution, the process errors out with following error:  [31mRequest "PUT https://upload.box.com/api/2.0/files/upload_sessions/FBCD32A57B4FAE03F7D0611E0FBF2713" failed with SSLError exception: SSLError(MaxRetryError("HTTPSConnectionPool(host='upload.box.com', port=443): Max retries exceeded with url: /api/2.0/files/upload_sessions/FBCD32A57B4FAE03F7D0611E0FBF2713 (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:2396)')))"))

I would like some help in understanding why this error keeps popping up. The upload is being done through a Service Account that has Co-Owner permissions to the folder that the data is being uploaded to.

Steps to Reproduce

  1. Create JWT credentials for custom app inside Box and store in local system
  2. Create python3 file which does only one single task - described in step 3
  3. Go to https://github.com/box/box-python-sdk/blob/main/docs/usage/files.md#manual-process
  4. Copy the code under there and paste in python3 code file created in step 2.
  5. Load the JWT creds from step 1 into a variable in the python code and use the following code to create an authenticated Box client: config = JWTAuth.from_settings_dictionary(jwtCredHolder) #jwtCredHolder is where the JWT is loaded into box_client = Client(config)
  6. Using dd if=/dev/urandom of=temp_20GB_file bs=1 count=0 seek=40g (MacOS) create a large 20 GB file
  7. Change references in the copied code such that it points to the file generated in step 5
  8. Execute the code

Expected Behavior

File upload completes successfully.

Error Message, Including Stack Trace

The following stack trace is when trying to upload a 20GB file. The SDK divided the file into 320 parts. The first two lines are part of my code that print out part#, part size and upload completion time.

  2022-10-14T15:08:09.709-04:00 112 of size 67108864 has been uploaded at
  2022-10-14T15:08:09.709-04:00 2022-10-14 19:07:44.144679
  2022-10-14T15:08:09.709-04:00 Request "PUT https://upload.box.com/api/2.0/files/upload_sessions/FBCD32A57B4FAE03F7D0611E0FBF2713" failed with SSLError exception: SSLError(MaxRetryError("HTTPSConnectionPool(host='upload.box.com', port=443): Max retries exceeded with url: /api/2.0/files/upload_sessions/FBCD32A57B4FAE03F7D0611E0FBF2713 (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:2396)')))"))
  2022-10-14T15:08:09.709-04:00 Traceback (most recent call last):
  2022-10-14T15:08:09.709-04:00 File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
  2022-10-14T15:08:09.709-04:00 httplib_response = self._make_request(
  2022-10-14T15:08:09.709-04:00 File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 398, in _make_request
  2022-10-14T15:08:09.709-04:00 conn.request(method, url, **httplib_request_kw)
  2022-10-14T15:08:09.709-04:00 File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 239, in request
  2022-10-14T15:08:09.709-04:00 super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  2022-10-14T15:08:09.709-04:00 File "/usr/local/lib/python3.10/http/client.py", line 1282, in request
  2022-10-14T15:08:09.709-04:00 self._send_request(method, url, body, headers, encode_chunked)
  2022-10-14T15:08:09.709-04:00 File "/usr/local/lib/python3.10/http/client.py", line 1328, in _send_request
  2022-10-14T15:08:09.709-04:00 self.endheaders(body, encode_chunked=encode_chunked)
  2022-10-14T15:08:09.709-04:00 File "/usr/local/lib/python3.10/http/client.py", line 1277, in endheaders
  2022-10-14T15:08:09.709-04:00 self._send_output(message_body, encode_chunked=encode_chunked)
  2022-10-14T15:08:09.709-04:00 File "/usr/local/lib/python3.10/http/client.py", line 1076, in _send_output
  2022-10-14T15:08:09.709-04:00 self.send(chunk)
  2022-10-14T15:08:09.709-04:00 File "/usr/local/lib/python3.10/http/client.py", line 998, in send
  2022-10-14T15:08:09.709-04:00 self.sock.sendall(data)
  2022-10-14T15:08:09.709-04:00 File "/usr/local/lib/python3.10/ssl.py", line 1237, in sendall
  2022-10-14T15:08:09.709-04:00 v = self.send(byte_view[count:])
  2022-10-14T15:08:09.709-04:00 File "/usr/local/lib/python3.10/ssl.py", line 1206, in send
  2022-10-14T15:08:09.709-04:00 return self._sslobj.write(data)
  2022-10-14T15:08:09.709-04:00 ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:2396)
  2022-10-14T15:08:09.709-04:00 During handling of the above exception, another exception occurred:
  2022-10-14T15:08:09.709-04:00 Traceback (most recent call last):
  2022-10-14T15:08:09.709-04:00 File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
  2022-10-14T15:08:09.709-04:00 resp = conn.urlopen(
  2022-10-14T15:08:09.709-04:00 File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 787, in urlopen
  2022-10-14T15:08:09.709-04:00 retries = retries.increment(
  2022-10-14T15:08:09.709-04:00 File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line 592, in increment
  2022-10-14T15:08:09.709-04:00 raise MaxRetryError(_pool, url, error or ResponseError(cause))
  2022-10-14T15:08:09.709-04:00 urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='upload.box.com', port=443): Max retries exceeded with url: /api/2.0/files/upload_sessions/FBCD32A57B4FAE03F7D0611E0FBF2713 (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:2396)')))
  2022-10-14T15:08:09.709-04:00 During handling of the above exception, another exception occurred:
  2022-10-14T15:08:09.709-04:00 Traceback (most recent call last):
  2022-10-14T15:08:09.709-04:00 File "//box-upload-jwt.py", line 156, in
  2022-10-14T15:08:09.709-04:00 get_secret()
  2022-10-14T15:08:09.709-04:00 File "//box-upload-jwt.py", line 31, in get_secret
  2022-10-14T15:08:09.709-04:00 upload_to_box(get_secret_value_response,requestData)
  2022-10-14T15:08:09.709-04:00 File "//box-upload-jwt.py", line 101, in upload_to_box
  2022-10-14T15:08:09.709-04:00 uploaded_part = upload_session.upload_part_bytes(chunk, part_num*upload_session.part_size, file_size)
  2022-10-14T15:08:09.709-04:00 File "/usr/local/lib/python3.10/site-packages/boxsdk/util/api_call_decorator.py", line 63, in call
  2022-10-14T15:08:09.709-04:00 return method(*args, **kwargs)
  2022-10-14T15:08:09.710-04:00 File "/usr/local/lib/python3.10/site-packages/boxsdk/object/upload_session.py", line 89, in upload_part_bytes
  2022-10-14T15:08:09.710-04:00 response = self._session.put(
  2022-10-14T15:08:09.710-04:00 File "/usr/local/lib/python3.10/site-packages/boxsdk/session/session.py", line 106, in put
  2022-10-14T15:08:09.710-04:00 return self.request('PUT', url, **kwargs)
  2022-10-14T15:08:09.710-04:00 File "/usr/local/lib/python3.10/site-packages/boxsdk/session/session.py", line 134, in request
  2022-10-14T15:08:09.710-04:00 response = self._prepare_and_send_request(method, url, **kwargs)
  2022-10-14T15:08:09.710-04:00 File "/usr/local/lib/python3.10/site-packages/boxsdk/session/session.py", line 325, in _prepare_and_send_request
  2022-10-14T15:08:09.710-04:00 network_response = self._send_request(request, **kwargs)
  2022-10-14T15:08:09.710-04:00 File "/usr/local/lib/python3.10/site-packages/boxsdk/session/session.py", line 529, in _send_request
  2022-10-14T15:08:09.710-04:00 return super()._send_request(request, **kwargs)
  2022-10-14T15:08:09.711-04:00 File "/usr/local/lib/python3.10/site-packages/boxsdk/session/session.py", line 436, in _send_request
  2022-10-14T15:08:09.711-04:00 network_response = self._network_layer.request(
  2022-10-14T15:08:09.711-04:00 File "/usr/local/lib/python3.10/site-packages/boxsdk/network/default_network.py", line 43, in request
  2022-10-14T15:08:09.711-04:00 request_response=self._session.request(method, url, **kwargs),
  2022-10-14T15:08:09.711-04:00 File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
  2022-10-14T15:08:09.712-04:00 resp = self.send(prep, **send_kwargs)
  2022-10-14T15:08:09.712-04:00 File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
  2022-10-14T15:08:09.712-04:00 r = adapter.send(request, **kwargs)
  2022-10-14T15:08:09.713-04:00 File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 563, in send
  2022-10-14T15:08:09.713-04:00 raise SSLError(e, request=request)
  2022-10-14T15:08:09.713-04:00Copyrequests.exceptions.SSLError: HTTPSConnectionPool(host='upload.box.com', port=443): Max retries exceeded with url: /api/2.0/files/upload_sessions/FBCD32A57B4FAE03F7D0611E0FBF2713 (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:2396)'))) requests.exceptions.SSLError: HTTPSConnectionPool(host='upload.box.com', port=443): Max retries exceeded with url: /api/2.0/files/upload_sessions/FBCD32A57B4FAE03F7D0611E0FBF2713 (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:2396)')))

Versions Used

Python SDK: boxsdk-3.5.0 Python: Python 3.9.13

lukaszsocha2 commented 1 year ago

Hi @SakethValiveti, thanks for posting this issue. This issue is currently under extensive investigation. We will get back to you as soon as we will find out the cause. @lukaszsocha2

lukaszsocha2 commented 1 year ago

Hi @SakethValiveti, I was able to reproduce this error only using Python 3.10.4. With Python 3.9.13 upload works for me without any error. Can you send me your entire python environment details(pip freeze) to be able to replicate your env on my side. You can try to make an upload after updating all dependencies - you can try with my dependencies:

attrs==22.1.0
boxsdk==3.5.0
certifi==2022.9.24
cffi==1.15.1
charset-normalizer==2.1.1
cryptography==38.0.1
idna==3.4
pycparser==2.21
PyJWT==2.5.0
python-dateutil==2.8.2
requests==2.28.1
requests-toolbelt==0.10.0
six==1.16.0
urllib3==1.26.12

So please let me know what is your current setup and if it helped to upgrade all dependencies. @lukaszsocha2

SakethValiveti commented 1 year ago

hi @lukaszsocha2, I'm using docker to run this process. The container has internet access and authenticates using JWT. The JWT points to a service account that is classified as "Co-Owner" to a specific folder to which all files are being uploaded to. It is using Python 3.9.15. OpenSSL version is 1.1.1n. Since you mentioned you had it run successfully through the provided dependency list, I tried using the dependencies you provided. I hit this error after part #172 was uploaded:

172 of size 67108864 has been uploaded at

  | 2022-10-19T11:34:45.320-04:00 | 2022-10-19 15:34:30.989559   | 2022-10-19T11:34:45.320-04:00 | Traceback (most recent call last):   | 2022-10-19T11:34:45.320-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen   | 2022-10-19T11:34:45.320-04:00 | httplib_response = self._make_request(   | 2022-10-19T11:34:45.320-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 449, in _make_request   | 2022-10-19T11:34:45.320-04:00 | six.raise_from(e, None)   | 2022-10-19T11:34:45.320-04:00 | File "", line 3, in raise_from   | 2022-10-19T11:34:45.320-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 444, in _make_request   | 2022-10-19T11:34:45.320-04:00 | httplib_response = conn.getresponse()   | 2022-10-19T11:34:45.320-04:00 | File "/usr/local/lib/python3.9/http/client.py", line 1377, in getresponse   | 2022-10-19T11:34:45.320-04:00 | response.begin()   | 2022-10-19T11:34:45.320-04:00 | File "/usr/local/lib/python3.9/http/client.py", line 320, in begin   | 2022-10-19T11:34:45.320-04:00 | version, status, reason = self._read_status()   | 2022-10-19T11:34:45.320-04:00 | File "/usr/local/lib/python3.9/http/client.py", line 281, in _read_status   | 2022-10-19T11:34:45.321-04:00 | line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")   | 2022-10-19T11:34:45.321-04:00 | File "/usr/local/lib/python3.9/socket.py", line 704, in readinto   | 2022-10-19T11:34:45.321-04:00 | return self._sock.recv_into(b)   | 2022-10-19T11:34:45.321-04:00 | File "/usr/local/lib/python3.9/ssl.py", line 1242, in recv_into   | 2022-10-19T11:34:45.321-04:00 | return self.read(nbytes, buffer)   | 2022-10-19T11:34:45.321-04:00 | File "/usr/local/lib/python3.9/ssl.py", line 1100, in read   | 2022-10-19T11:34:45.322-04:00 | return self._sslobj.read(len, buffer)   | 2022-10-19T11:34:45.322-04:00 | ConnectionResetError: [Errno 104] Connection reset by peer   | 2022-10-19T11:34:45.322-04:00 | During handling of the above exception, another exception occurred:   | 2022-10-19T11:34:45.322-04:00 | Traceback (most recent call last):   | 2022-10-19T11:34:45.322-04:00 | File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 489, in send   | 2022-10-19T11:34:45.322-04:00 | resp = conn.urlopen(   | 2022-10-19T11:34:45.322-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 787, in urlopen   | 2022-10-19T11:34:45.322-04:00 | retries = retries.increment(   | 2022-10-19T11:34:45.322-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 550, in increment   | 2022-10-19T11:34:45.323-04:00 | raise six.reraise(type(error), error, _stacktrace)   | 2022-10-19T11:34:45.323-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/packages/six.py", line 769, in reraise   | 2022-10-19T11:34:45.323-04:00 | raise value.with_traceback(tb)   | 2022-10-19T11:34:45.323-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen   | 2022-10-19T11:34:45.323-04:00 | httplib_response = self._make_request(   | 2022-10-19T11:34:45.323-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 449, in _make_request   | 2022-10-19T11:34:45.323-04:00 | six.raise_from(e, None)   | 2022-10-19T11:34:45.323-04:00 | File "", line 3, in raise_from   | 2022-10-19T11:34:45.323-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 444, in _make_request   | 2022-10-19T11:34:45.324-04:00 | httplib_response = conn.getresponse()   | 2022-10-19T11:34:45.324-04:00 | File "/usr/local/lib/python3.9/http/client.py", line 1377, in getresponse   | 2022-10-19T11:34:45.324-04:00 | response.begin()   | 2022-10-19T11:34:45.324-04:00 | File "/usr/local/lib/python3.9/http/client.py", line 320, in begin   | 2022-10-19T11:34:45.324-04:00 | version, status, reason = self._read_status()   | 2022-10-19T11:34:45.324-04:00 | File "/usr/local/lib/python3.9/http/client.py", line 281, in _read_status   | 2022-10-19T11:34:45.324-04:00 | line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")   | 2022-10-19T11:34:45.324-04:00 | File "/usr/local/lib/python3.9/socket.py", line 704, in readinto   | 2022-10-19T11:34:45.325-04:00 | return self._sock.recv_into(b)   | 2022-10-19T11:34:45.325-04:00 | File "/usr/local/lib/python3.9/ssl.py", line 1242, in recv_into   | 2022-10-19T11:34:45.325-04:00 | return self.read(nbytes, buffer)   | 2022-10-19T11:34:45.325-04:00 | File "/usr/local/lib/python3.9/ssl.py", line 1100, in read   | 2022-10-19T11:34:45.326-04:00 | return self._sslobj.read(len, buffer)   | 2022-10-19T11:34:45.326-04:00 | urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))   | 2022-10-19T11:34:45.326-04:00 | During handling of the above exception, another exception occurred:   | 2022-10-19T11:34:45.326-04:00 | Traceback (most recent call last):   | 2022-10-19T11:34:45.326-04:00 | File "//box-upload-jwt.py", line 190, in   | 2022-10-19T11:34:45.326-04:00 | get_secret()   | 2022-10-19T11:34:45.326-04:00 | File "//box-upload-jwt.py", line 33, in get_secret   | 2022-10-19T11:34:45.326-04:00 | upload_to_box(get_secret_value_response,requestData)   | 2022-10-19T11:34:45.326-04:00 | File "//box-upload-jwt.py", line 126, in upload_to_box   | 2022-10-19T11:34:45.326-04:00 | uploaded_part = upload_session.upload_part_bytes(chunk, part_numupload_session.part_size, file_size)   | 2022-10-19T11:34:45.326-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/util/api_call_decorator.py", line 63, in call   | 2022-10-19T11:34:45.326-04:00 | return method(args, kwargs)   | 2022-10-19T11:34:45.326-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/object/upload_session.py", line 89, in upload_part_bytes   | 2022-10-19T11:34:45.326-04:00 | response = self._session.put(   | 2022-10-19T11:34:45.326-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/session/session.py", line 106, in put   | 2022-10-19T11:34:45.326-04:00 | return self.request('PUT', url, kwargs)   | 2022-10-19T11:34:45.326-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/session/session.py", line 134, in request   | 2022-10-19T11:34:45.326-04:00 | response = self._prepare_and_send_request(method, url, kwargs)   | 2022-10-19T11:34:45.326-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/session/session.py", line 328, in _prepare_and_send_request   | 2022-10-19T11:34:45.327-04:00 | retry = self._get_retry_request_callable(network_response, attempt_number, request, kwargs)   | 2022-10-19T11:34:45.327-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/session/session.py", line 503, in _get_retry_request_callable   | 2022-10-19T11:34:45.327-04:00 | self._renew_session(network_response.access_token_used)   | 2022-10-19T11:34:45.327-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/session/session.py", line 475, in _renew_session   | 2022-10-19T11:34:45.327-04:00 | new_accesstoken, = self._oauth.refresh(access_token_used)   | 2022-10-19T11:34:45.327-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/auth/oauth2.py", line 221, in refresh   | 2022-10-19T11:34:45.327-04:00 | access_token, refresh_token = self._refresh(access_token_to_refresh)   | 2022-10-19T11:34:45.327-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/auth/server_auth.py", line 40, in _refresh   | 2022-10-19T11:34:45.327-04:00 | new_access_token = self.authenticate_instance()   | 2022-10-19T11:34:45.327-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/auth/server_auth.py", line 103, in authenticate_instance   | 2022-10-19T11:34:45.328-04:00 | return self._authenticate(self._enterprise_id, self.ENTERPRISE_SUBJECT_TYPE)   | 2022-10-19T11:34:45.328-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/auth/server_auth.py", line 124, in _authenticate   | 2022-10-19T11:34:45.328-04:00 | return self._fetch_access_token(subject_id, subject_type, date)   | 2022-10-19T11:34:45.328-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/auth/jwt_auth.py", line 181, in _fetch_access_token   | 2022-10-19T11:34:45.328-04:00 | return self.send_token_request(data, access_token=None, expect_refresh_token=False)[0]   | 2022-10-19T11:34:45.328-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/auth/oauth2.py", line 349, in send_token_request   | 2022-10-19T11:34:45.328-04:00 | token_response = self._execute_token_request(data, access_token, expect_refresh_token)   | 2022-10-19T11:34:45.328-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/auth/oauth2.py", line 287, in _execute_token_request   | 2022-10-19T11:34:45.328-04:00 | network_response = self._session.request(   | 2022-10-19T11:34:45.328-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/session/session.py", line 134, in request   | 2022-10-19T11:34:45.328-04:00 | response = self._prepare_and_send_request(method, url, kwargs)   | 2022-10-19T11:34:45.328-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/session/session.py", line 325, in _prepare_and_send_request   | 2022-10-19T11:34:45.328-04:00 | network_response = self._send_request(request, kwargs)   | 2022-10-19T11:34:45.328-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/session/session.py", line 436, in _send_request   | 2022-10-19T11:34:45.329-04:00 | network_response = self._network_layer.request(   | 2022-10-19T11:34:45.329-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/network/default_network.py", line 43, in request   | 2022-10-19T11:34:45.329-04:00 | request_response=self._session.request(method, url, kwargs),   | 2022-10-19T11:34:45.329-04:00 | File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 587, in request   | 2022-10-19T11:34:45.329-04:00 | resp = self.send(prep, send_kwargs)   | 2022-10-19T11:34:45.329-04:00 | File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 701, in send   | 2022-10-19T11:34:45.329-04:00 | r = adapter.send(request, **kwargs)   | 2022-10-19T11:34:45.329-04:00 | File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 547, in send   | 2022-10-19T11:34:45.330-04:00 | raise ConnectionError(err, request=request)   | 2022-10-19T11:34:45.330-04:00 | requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

Please advise next steps.

lukaszsocha2 commented 1 year ago

@SakethValiveti is it possible to share your Dockerfile so that I could have exactly same environment as you? You can send it to my e-mail: lsocha@box.com. @lukaszsocha2

lukaszsocha2 commented 1 year ago

As a temporary workaround I would recommend to try to authenticate more often by reinitialising you client object, e.g. around each 30 minutes. This should prevent this error from happening until we will identify and solve this error in the correct way.

SakethValiveti commented 1 year ago

Hi @lukaszsocha2 I sent the Dockerfile to your email but have a few questions I was hoping you could help me out with.

I thought each authentication count towards to API limits, so I just introduced a time.sleep() of 1 second in between each chunk being uploaded, and this helped with not getting this error.

However, the script ran for over 4 hours for a 20GB file which seems to be way too long even for a 20GB file (I killed the container after the 4 hours, and I'm currently working on getting the logs from there). Could you please help me understand if there's any limits to how fast and how much I can upload to Box.com? Do you have any prior testing statistics you could share with me which would indicate file size vs time-to-upload metric?

Further, I noticed the chunk size is set to 67 MB and that for a 50GB file the SDK splits it into 800 chunks. Can this be modified into say 50 1GB chunks?

SakethValiveti commented 1 year ago

Hi @lukaszsocha2 after gathering the logs, it looks like it hit a similar error as initially reported. Please find below the stacktrace.

195 of size 67108864 has been uploaded at

  | 2022-10-20T12:04:34.785-04:00 | 2022-10-20 16:04:34.785076   | 2022-10-20T12:04:48.057-04:00 | Request "PUT https://upload.box.com/api/2.0/files/upload_sessions/65B5F1B4EC74880EF1CBBE6D2C2798AE" failed with SSLError exception: SSLError(MaxRetryError("HTTPSConnectionPool(host='upload.box.com', port=443): Max retries exceeded with url: /api/2.0/files/upload_sessions/65B5F1B4EC74880EF1CBBE6D2C2798AE (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)')))"))   | 2022-10-20T12:04:48.057-04:00 | Traceback (most recent call last):   | 2022-10-20T12:04:48.057-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen   | 2022-10-20T12:04:48.057-04:00 | httplib_response = self._make_request(   | 2022-10-20T12:04:48.057-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 386, in _make_request   | 2022-10-20T12:04:48.057-04:00 | self._validate_conn(conn)   | 2022-10-20T12:04:48.057-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1042, in _validate_conn   | 2022-10-20T12:04:48.058-04:00 | conn.connect()   | 2022-10-20T12:04:48.058-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 414, in connect   | 2022-10-20T12:04:48.058-04:00 | self.sock = ssl_wrapsocket(   | 2022-10-20T12:04:48.058-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/util/ssl.py", line 449, in ssl_wrap_socket   | 2022-10-20T12:04:48.058-04:00 | ssl_sock = _ssl_wrap_socketimpl(   | 2022-10-20T12:04:48.058-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/util/ssl.py", line 493, in _ssl_wrap_socket_impl   | 2022-10-20T12:04:48.058-04:00 | return ssl_context.wrap_socket(sock, server_hostname=server_hostname)   | 2022-10-20T12:04:48.058-04:00 | File "/usr/local/lib/python3.9/ssl.py", line 501, in wrap_socket   | 2022-10-20T12:04:48.059-04:00 | return self.sslsocket_class._create(   | 2022-10-20T12:04:48.059-04:00 | File "/usr/local/lib/python3.9/ssl.py", line 1041, in _create   | 2022-10-20T12:04:48.059-04:00 | self.do_handshake()   | 2022-10-20T12:04:48.059-04:00 | File "/usr/local/lib/python3.9/ssl.py", line 1310, in do_handshake   | 2022-10-20T12:04:48.060-04:00 | self._sslobj.do_handshake()   | 2022-10-20T12:04:48.060-04:00 | ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1129)   | 2022-10-20T12:04:48.060-04:00 | During handling of the above exception, another exception occurred:   | 2022-10-20T12:04:48.060-04:00 | Traceback (most recent call last):   | 2022-10-20T12:04:48.060-04:00 | File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 489, in send   | 2022-10-20T12:04:48.060-04:00 | resp = conn.urlopen(   | 2022-10-20T12:04:48.060-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 787, in urlopen   | 2022-10-20T12:04:48.060-04:00 | retries = retries.increment(   | 2022-10-20T12:04:48.060-04:00 | File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 592, in increment   | 2022-10-20T12:04:48.060-04:00 | raise MaxRetryError(_pool, url, error or ResponseError(cause))   | 2022-10-20T12:04:48.060-04:00 | urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='upload.box.com', port=443): Max retries exceeded with url: /api/2.0/files/upload_sessions/65B5F1B4EC74880EF1CBBE6D2C2798AE (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)')))   | 2022-10-20T12:04:48.060-04:00 | During handling of the above exception, another exception occurred:   | 2022-10-20T12:04:48.060-04:00 | Traceback (most recent call last):   | 2022-10-20T12:04:48.060-04:00 | File "//box-upload-jwt.py", line 187, in   | 2022-10-20T12:04:48.061-04:00 | get_secret()   | 2022-10-20T12:04:48.061-04:00 | File "//box-upload-jwt.py", line 33, in get_secret   | 2022-10-20T12:04:48.061-04:00 | upload_to_box(get_secret_value_response,requestData)   | 2022-10-20T12:04:48.061-04:00 | File "//box-upload-jwt.py", line 123, in upload_to_box   | 2022-10-20T12:04:48.061-04:00 | uploaded_part = upload_session.upload_part_bytes(chunk, part_numupload_session.part_size, file_size)   | 2022-10-20T12:04:48.061-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/util/api_call_decorator.py", line 63, in call   | 2022-10-20T12:04:48.061-04:00 | return method(args, kwargs)   | 2022-10-20T12:04:48.061-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/object/upload_session.py", line 89, in upload_part_bytes   | 2022-10-20T12:04:48.061-04:00 | response = self._session.put(   | 2022-10-20T12:04:48.061-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/session/session.py", line 106, in put   | 2022-10-20T12:04:48.061-04:00 | return self.request('PUT', url, kwargs)   | 2022-10-20T12:04:48.061-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/session/session.py", line 134, in request   | 2022-10-20T12:04:48.061-04:00 | response = self._prepare_and_send_request(method, url, kwargs)   | 2022-10-20T12:04:48.061-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/session/session.py", line 325, in _prepare_and_send_request   | 2022-10-20T12:04:48.061-04:00 | network_response = self._send_request(request, kwargs)   | 2022-10-20T12:04:48.061-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/session/session.py", line 529, in _send_request   | 2022-10-20T12:04:48.062-04:00 | return super()._send_request(request, kwargs)   | 2022-10-20T12:04:48.062-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/session/session.py", line 436, in _send_request   | 2022-10-20T12:04:48.062-04:00 | network_response = self._network_layer.request(   | 2022-10-20T12:04:48.062-04:00 | File "/usr/local/lib/python3.9/site-packages/boxsdk/network/default_network.py", line 43, in request   | 2022-10-20T12:04:48.062-04:00 | request_response=self._session.request(method, url, kwargs),   | 2022-10-20T12:04:48.062-04:00 | File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 587, in request   | 2022-10-20T12:04:48.062-04:00 | resp = self.send(prep, send_kwargs)   | 2022-10-20T12:04:48.062-04:00 | File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 701, in send   | 2022-10-20T12:04:48.063-04:00 | r = adapter.send(request, kwargs)   | 2022-10-20T12:04:48.063-04:00 | File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 563, in send   | 2022-10-20T12:04:48.063-04:00 | raise SSLError(e, request=request)   | 2022-10-20T12:04:48.063-04:00 | requests.exceptions.SSLError: HTTPSConnectionPool(host='upload.box.com', port=443): Max retries exceeded with url: /api/2.0/files/upload_sessions/65B5F1B4EC74880EF1CBBE6D2C2798AE (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)')))

lukaszsocha2 commented 1 year ago

Hi @SakethValiveti, sorry for late response - I was on leave. Box has some rate limiters limiting the volume of requests or actions that can be made against a specific service or feature including upload service. But if this was the case the error returned by API would say this explicitly: "Too many requests" with 429 status code. For me it still looks like more [SSL/requests library/Python language version] issue, cause for me this occurs only when using some Python versions, e.g. when using Python 3.6 it doesn't happen at all. Can you maybe confirm this on your side that Python 3.6 works fine?

It is not possible to set custom size of chunks - they are determined by service when creating upload session see API spec.

Thanks for sending email with DockerFile. I'll try to use it now and see if the same error as yours will occur. Best, @lukaszsocha2

lukaszsocha2 commented 1 year ago

Hi @SakethValiveti, can you please test if this pr fix your issue - could you checkout branch sdk-2732-fix-connection-reset-error and use code from this branch to execute the code like before. Then please tell me if the issue still occurs? Please don't change default socket options for this test as you did above.

So I will be very grateful if you could verify if this fix helps. Unfortunately this error is so indeterministic and I wasn't able to reproduce it on my own so I cannot be sure that this error will be gone now. Best, @lukaszsocha2