Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 Bucket no Encoding Type #816

Closed
Cam1337 opened this issue Sep 20, 2016 · 7 comments
Closed

S3 Bucket no Encoding Type #816

Cam1337 opened this issue Sep 20, 2016 · 7 comments
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. question

Comments

@Cam1337
Copy link

Cam1337 commented Sep 20, 2016

Is it possible to make a request with no encoding type? I am performing:

s3 = boto3.resource("s3")
bucket = s3.Bucket("myBucket")
objs = bucket.objects.filter(EncodingType=None, Prefix="foo")

This is still performing a GET request with ?encoding-type=url. Interestingly, the keys returned are only being formatted in URL encoding if the encoding type is specified accordingly, but the request is sending the parameter to url-encode the results every time.

http://boto3.readthedocs.io/en/latest/reference/services/s3.html?highlight=encodingType#S3.Bucket.objects

@JordonPhillips
Copy link
Contributor

Encoding type is automatically set because there are unicode characters which can break the XML parser. To work around the issue, we automatically set the encoding type parameter to url if the customer hasn't already set it. We then decode the keys on the way back, again only if we provided that parameter. See boto/botocore#726 for more details.

What's your reasoning for wanting to omit the parameter?

@JordonPhillips JordonPhillips added question closing-soon This issue will automatically close in 4 days unless further comments are made. labels Sep 23, 2016
@Cam1337
Copy link
Author

Cam1337 commented Sep 23, 2016

Is there a way to force the parameter to false or to avoid the XML parser and deal with raw output? None of the data that I am using has unicode characters, so I would like to force execution without url-encoding. Additionally, I don't know if s3 does any additional internal work depending on url-encoding specification, but it would be nice to be able to check that out.

@Cam1337
Copy link
Author

Cam1337 commented Sep 28, 2016

Any update?

@JordonPhillips
Copy link
Contributor

JordonPhillips commented Sep 28, 2016

You can unregister the handler on the client like so:

import boto3
from boto3.session import Session
from botocore.handlers import set_list_objects_encoding_type_url


s3 = boto3.client('s3')
s3.meta.events.unregister(
    'before-parameter-build.s3.ListObjects',
    set_list_objects_encoding_type_url)

# Unregister from a session
sess = Session()
sess.events.unregister(
    'before-parameter-build.s3.ListObjects',
    set_list_objects_encoding_type_url)

@Cam1337
Copy link
Author

Cam1337 commented Sep 28, 2016

@JordonPhillips,

Thank you for your response. I will give that a try.

@tachang
Copy link

tachang commented Sep 7, 2017

The reason is because Google Cloud storage gives this:

<?xml version='1.0' encoding='UTF-8'?><Error><Code>InvalidArgument</Code><Message>Invalid argument.</Message><Details>Invalid query parameter(s): [encoding-type]</Details></Error>

@gleicon
Copy link

gleicon commented Dec 18, 2017

Put together a gist, hope it helps. I understand that boto3 belongs to aws and interoperability is an interim configuration but it required knowing more about s3 protocol than I wanted.

https://gist.github.com/gleicon/2b8acb9f9c0f22753eaac227ff997b34

tipabu added a commit to tipabu/s3-tests that referenced this issue Nov 25, 2019
Following boto/botocore#726, list_objects will
automatically include a encoding-type=url query param. However, the
client does not decode all of the response elements properly -- notably,
Prefix would remain encoded.

Hopefully this will be fixed soon-ish (I've got a patch proposed at
boto/botocore#1901) but in the meantime, use the
work-around suggested in boto/boto3#816 of
unregistering the set_list_objects_encoding_type_url handler.

Signed-off-by: Tim Burke <tim.burke@gmail.com>
tipabu added a commit to tipabu/s3-tests that referenced this issue Apr 4, 2022
Following boto/botocore#726, list_objects will
automatically include a encoding-type=url query param. However, the
client does not decode all of the response elements properly -- notably,
Prefix would remain encoded.

Hopefully this will be fixed soon-ish (I've got a patch proposed at
boto/botocore#1901) but in the meantime, use the
work-around suggested in boto/boto3#816 of
unregistering the set_list_objects_encoding_type_url handler.

Signed-off-by: Tim Burke <tim.burke@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. question
Projects
None yet
Development

No branches or pull requests

5 participants