When I run this code:
bucket_name = self.myBucket['PhysicalResourceId'] #evaluates to 'myBucket234342'
some_binary_data = b'Here we have some data'
S3client.put_object(Body=some_binary_data, Bucket=bucket_name, Key='hello.txt')
I get this error:
TypeError: can only concatenate str (not "dict") to str
With this stack trace:
ERROR [0.333s]: test_cant_access_encrypted_files_unless_authorized (testS3Security.TestS3Security)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\ddrayton\Desktop\template-build-s3\tests\testS3Security.py", line 130, in test_cant_access_encrypted_files_unless_authorized
S3client.put_object(Body=some_binary_data, Bucket=bucket_name, Key='helloencrypt.txt')
File "C:\Users\ddrayton\AppData\Roaming\Python\Python37\site-packages\botocore\client.py", line 320, in _api_call
return self._make_api_call(operation_name, kwargs)
File "C:\Users\ddrayton\AppData\Roaming\Python\Python37\site-packages\botocore\client.py", line 610, in _make_api_call
operation_model, request_dict)
File "C:\Users\ddrayton\AppData\Roaming\Python\Python37\site-packages\botocore\endpoint.py", line 102, in make_request
return self._send_request(request_dict, operation_model)
File "C:\Users\ddrayton\AppData\Roaming\Python\Python37\site-packages\botocore\endpoint.py", line 132, in _send_request
request = self.create_request(request_dict, operation_model)
File "C:\Users\ddrayton\AppData\Roaming\Python\Python37\site-packages\botocore\endpoint.py", line 116, in create_request
operation_name=operation_model.name)
File "C:\Users\ddrayton\AppData\Roaming\Python\Python37\site-packages\botocore\hooks.py", line 356, in emit
return self._emitter.emit(aliased_event_name, **kwargs)
File "C:\Users\ddrayton\AppData\Roaming\Python\Python37\site-packages\botocore\hooks.py", line 228, in emit
return self._emit(event_name, kwargs)
File "C:\Users\ddrayton\AppData\Roaming\Python\Python37\site-packages\botocore\hooks.py", line 211, in _emit
response = handler(**kwargs)
File "C:\Users\ddrayton\AppData\Roaming\Python\Python37\site-packages\botocore\signers.py", line 90, in handler
return self.sign(operation_name, request)
File "C:\Users\ddrayton\AppData\Roaming\Python\Python37\site-packages\botocore\signers.py", line 157, in sign
auth.add_auth(request)
File "C:\Users\ddrayton\AppData\Roaming\Python\Python37\site-packages\botocore\auth.py", line 425, in add_auth
super(S3SigV4Auth, self).add_auth(request)
File "C:\Users\ddrayton\AppData\Roaming\Python\Python37\site-packages\botocore\auth.py", line 368, in add_auth
signature = self.signature(string_to_sign, request)
File "C:\Users\ddrayton\AppData\Roaming\Python\Python37\site-packages\botocore\auth.py", line 348, in signature
k_date = self._sign(('AWS4' + key).encode('utf-8'),
TypeError: can only concatenate str (not "dict") to str
Normally, that error just means you can't combine a dictionary with a string. That makes sense. But the only argument I'm passing here that's supposed to be a string, that's not a literal string itself, is bucket_name, and I'm sure that's a string because I did:
print(type(bucket_name))
... and it returned string.
And the body I don't think Body is causing any problems (per this example). Body is of type 'bytes,' according to the docs.
The stack trace makes me wonder if it's a bug with Boto3 itself... but I doubt it. What am I doing wrong?