botocore.exceptions.ClientError: An error occurred (InvalidArgument) when calling the PutObject operation: Unknown

I was following a tutorial by digital ocean on linking spaces with my django project,

I am currently getting this error:

  File "G:\Projects\Python\Django\laterevision\src\", line 22, in <module>
  File "G:\Projects\Python\Django\laterevision\src\", line 18, in main
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\django\core\management\", line 446, in execute_from_command_line
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\django\core\management\", line 440, in execute
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\django\core\management\", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\django\core\management\", line 448, in execute
    output = self.handle(*args, **options)
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\django\contrib\staticfiles\management\commands\", line 209, in handle
    collected = self.collect()
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\django\contrib\staticfiles\management\commands\", line 135, in collect
    handler(path, prefixed_path, storage)
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\django\contrib\staticfiles\management\commands\", line 378, in copy_file, source_file)
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\django\core\files\", line 56, in save
    name = self._save(name, content)
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\storages\backends\", line 457, in _save
    obj.upload_fileobj(content, ExtraArgs=params, Config=self._transfer_config)
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\boto3\s3\", line 725, in object_upload_fileobj
    return self.meta.client.upload_fileobj(
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\boto3\s3\", line 636, in upload_fileobj
    return future.result()
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\s3transfer\", line 103, in result
    return self._coordinator.result()
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\s3transfer\", line 266, in result
    raise self._exception
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\s3transfer\", line 139, in __call__
    return self._execute_main(kwargs)
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\s3transfer\", line 162, in _execute_main
    return_value = self._main(**kwargs)
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\s3transfer\", line 758, in _main
    client.put_object(Bucket=bucket, Key=key, Body=body, **extra_args)
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\botocore\", line 514, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "G:\Projects\Python\Django\laterevision\venv\lib\site-packages\botocore\", line 938, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidArgument) when calling the PutObject operation: Unknown

My settings for spaces look like this:

# Static files (CSS, JavaScript, Images)


# I enabled the CDN, so you get a custom domain. Use the end point in the AWS_S3_CUSTOM_DOMAIN setting. 
    'CacheControl': 'max-age=86400',

AWS_DEFAULT_ACL = 'x-amz-acl'

STATICFILES_STORAGE = 'custom_storages.StaticStorage'
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'

# Use AWS_S3_ENDPOINT_URL here if you haven't enabled the CDN and got a custom domain. 
STATIC_URL = '{}/{}/'.format(AWS_S3_CUSTOM_DOMAIN, 'static')
STATIC_ROOT = 'static/'

MEDIA_URL = '{}/{}/'.format(AWS_S3_CUSTOM_DOMAIN, 'media')
MEDIA_ROOT = 'media/'

and custom_storages looks like this:

from storages.backends.s3boto3 import S3Boto3Storage

class StaticStorage(S3Boto3Storage):
	bucket_name = 'lrev'
	location = 'static'

class MediaStorage(S3Boto3Storage):
	bucket_name = 'lrev'
	location = 'media'

Any help would be appriciated!

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.

Bobby Iliev
Site Moderator
Site Moderator badge
October 21, 2022
Accepted Answer

Hi there,

I believe that the problem might be the following:


I think that is not a valid endpoint.

I would recommend using the following:

# Static files (CSS, JavaScript, Images)

AWS_ACCESS_KEY_ID = 'your-spaces-access-key'
AWS_SECRET_ACCESS_KEY = 'your-spaces-secret-access-key'
AWS_STORAGE_BUCKET_NAME = 'your-storage-bucket-name'
    'CacheControl': 'max-age=86400',
AWS_LOCATION = 'your-spaces-files-folder'

    os.path.join(BASE_DIR, 'mysite/static'),
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

Let me know how it goes!



Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel