boto3 Client Error: Server Side Encryption with Customer provided key is incompatible with the encryption method specified
<p>I'm using boto3 with my django application to upload some files to S3. But I receive the following error when I try to specify the client side encryption algorithm and and keys using <a href="https://boto3.readthedocs.io/en/latest/reference/services/s3.html#object" rel="nofollow">boto3's Object's API</a>.</p>

<blockquote>
  <p>An error occurred (InvalidArgument) when calling the PutObject
  operation: Server Side Encryption with Customer provided key is
  incompatible with the encryption method specified.</p>
</blockquote>

<p>Here is my code for specifying Encryption algorithm and keys.</p>

<pre><code>    import boto3
    s3 = boto3.resource('s3')
    key = s3.Object(bucket_name, key_name)
    file_obj.seek(0)
    kwargs = {
        'ServerSideEncryption': 'AES256',
        'SSECustomerAlgorithm': 'AES256',
        'SSECustomerKey': settings.AWS_ENCRYPTION_KEY,
    }

    key.put(**kwargs)
    key.put(Body=file_obj)
    key.Acl().put(ACL='public-read')
</code></pre>

<p>And here is how I generate the encryption key in settings.py </p>

<pre><code># settings.py
password = '32characterslongpassphraseneeded'.encode('utf-8')
AWS_ENCRYPTION_KEY = base64.b64encode(password)
</code></pre>

<h1>Update</h1>

<p>I'm using python3.</p>