Problem Uploading to Spaces with boto3


I’m trying to upload a file accoring to these instructions:

This is my code:

#!/bin/env python3
import boto3


key = 'KEY'
secret = 'SECRET'
space_name = 'my-space-name'

filename = 'test.7z'

session = boto3.session.Session()
client = session.client('s3',

client.upload_file(filename,  # Path to local file
                   space_name,  # Name of Space
                   filename)  # Name for remote file

However, the script never terminates and the upload fails. This is a part of the debug output:



2018-01-04 23:42:46,436 botocore.auth [DEBUG] StringToSign:
2018-01-04 23:42:46,436 botocore.auth [DEBUG] Signature:
2018-01-04 23:42:46,436 botocore.hooks [DEBUG] Event request-created.s3.PutObject: calling handler <function signal_transferring at 0x7f6df549a268>
2018-01-04 23:42:46,437 botocore.endpoint [DEBUG] Sending http request: <PreparedRequest [PUT]>
2018-01-04 23:42:46,438 botocore.vendored.requests.packages.urllib3.connectionpool [INFO] Starting new HTTPS connection (3):
2018-01-04 23:42:46,602 botocore.awsrequest [DEBUG] Waiting for 100 Continue response.
2018-01-04 23:42:46,633 botocore.awsrequest [DEBUG] 100 Continue response seen, now sending request body.

Eventually the connection times out and a new attempt will be made.

I can upload a very small file containing only test123. However, also there the scipt does not terminate as well. But the file will be visible in the space. The file I’m actually trying to upload is about 300kb.

I would greatly appreciate any help you might be able to give. Thank you very much!

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Most likely this was some sort of temporary local networking issue or issue with Spaces itself. If you experience something like this, it’s worth checking If that is not the case, there are some setting you can change that might help.

When uploading large files with the upload_file() function, boto3 will automatically use a “multipart upload.” This breaks the file into smaller chunks and uploads them separately. This can be very useful to prevent timeouts. By default, this will only happen for files over 8 MB, but this behavior is configurable. If you are still experiencing this problem and it wasn’t just a transient network issue, you might want to try setting a smaller threshold. For example, you could try:

config = boto3.s3.transfer.TransferConfig(multipart_threshold=50000,


See more about the available config options and their defaults here: