I'm able to generate a presigned url like so
import boto3
s3 = boto3.client('s3')
url = s3.generate_presigned_url( ClientMethod='list_objects', Params={'Bucket':'bucket-name'} )
# now get the listing
import requests
r = requests.get(url)
# r.status_code is 200
# Problem: r.text output is in XML format
When I do a direct call s3.list_objects(Bucket='bucket-name')
then I get the response in JSON. There is no option to specify content type when generating the url. I've tried updating the headers of the request with accept: application/json
, but that results in a "SignatureDoesNotMatch" error from AWS.
Ultimately I will be using the URL client-side with javascript. This example is just to illustrate the problem.
How do I get the response in JSON when using a presigned URL (preferably using boto)? Seems like it should be possible.
There is no way to do this, S3 only returns XML. boto3
has response parsing that converts it into a dictionary for ease of use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With