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

Fix url parsing for S3 #235

Merged
merged 1 commit into from
Sep 24, 2018
Merged

Conversation

rileypeterson
Copy link
Contributor

Add test for colon in key name of s3 uri. Apply bug fix on line 491 of smart_open/smart_open_lib.py. To my knowledge, other tests are still passing and this didn't introduce any regressions.

Let me know if there's anything else to do. For now we just downgraded to 1.6.0, but hoping to see this in the next release. Thanks!

…f smart_open/smart_open_lib.py. To my knowledge, other tests are still passing and this didn't introduce any regressions
@@ -84,7 +84,7 @@


Uri = collections.namedtuple(
'Uri',
'Uri',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My text editor did this 🤷‍♂️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's ok, don't worry

@menshikh-iv
Copy link
Contributor

Looks good for me, thanks @rileypeterson. If @mpenkov agree - we can merge this.

Copy link
Collaborator

@mpenkov mpenkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, let's merge.

@menshikh-iv menshikh-iv changed the title Resolution for Issue #234 Fix url parsing for S3 Sep 24, 2018
@menshikh-iv menshikh-iv merged commit efb74ce into piskvorky:master Sep 24, 2018
@gyscos
Copy link

gyscos commented Jul 18, 2023

Looks like the issue came back?
Getting:

>>> smart_open.open("s3://bucket/foo:bar@baz")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/abury/.local/lib/python3.10/site-packages/smart_open/smart_open_lib.py", line 224, in open
    binary = _open_binary_stream(uri, binary_mode, transport_params)
  File "/home/abury/.local/lib/python3.10/site-packages/smart_open/smart_open_lib.py", line 400, in _open_binary_stream
    fobj = submodule.open_uri(uri, mode, transport_params)
  File "/home/abury/.local/lib/python3.10/site-packages/smart_open/s3.py", line 221, in open_uri
    parsed_uri = parse_uri(uri)
  File "/home/abury/.local/lib/python3.10/site-packages/smart_open/s3.py", line 112, in parse_uri
    head, key_id = uri.split('/', 1)
ValueError: not enough values to unpack (expected 2, got 1)
>>> smart_open.open("s3://bucket/foo:bar@baz/boz")
Traceback (most recent call last):
  File "/home/abury/.local/lib/python3.10/site-packages/smart_open/s3.py", line 330, in _get
    return client.get_object(Bucket=bucket, Key=key, Range=range_string)
  File "/home/abury/.local/lib/python3.10/site-packages/botocore/client.py", line 530, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/home/abury/.local/lib/python3.10/site-packages/botocore/client.py", line 964, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (AuthorizationHeaderMalformed) when calling the GetObject operation: The authorization header is malformed; the Credential is mal-formed; expecting "<YOUR-AKID>/YYYYMMDD/REGION/SERVICE/aws4_request".

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/abury/.local/lib/python3.10/site-packages/smart_open/smart_open_lib.py", line 224, in open
    binary = _open_binary_stream(uri, binary_mode, transport_params)
  File "/home/abury/.local/lib/python3.10/site-packages/smart_open/smart_open_lib.py", line 400, in _open_binary_stream
    fobj = submodule.open_uri(uri, mode, transport_params)
  File "/home/abury/.local/lib/python3.10/site-packages/smart_open/s3.py", line 224, in open_uri
    return open(parsed_uri['bucket_id'], parsed_uri['key_id'], mode, **kwargs)
  File "/home/abury/.local/lib/python3.10/site-packages/smart_open/s3.py", line 291, in open
    fileobj = Reader(
  File "/home/abury/.local/lib/python3.10/site-packages/smart_open/s3.py", line 574, in __init__
    self.seek(0)
  File "/home/abury/.local/lib/python3.10/site-packages/smart_open/s3.py", line 666, in seek
    self._current_pos = self._raw_reader.seek(offset, whence)
  File "/home/abury/.local/lib/python3.10/site-packages/smart_open/s3.py", line 417, in seek
    self._open_body(start, stop)
  File "/home/abury/.local/lib/python3.10/site-packages/smart_open/s3.py", line 438, in _open_body
    response = _get(
  File "/home/abury/.local/lib/python3.10/site-packages/smart_open/s3.py", line 338, in _get
    raise wrapped_error from error
OSError: unable to access bucket: 'baz' key: 'boz' version: None error: An error occurred (AuthorizationHeaderMalformed) when calling the GetObject operation: The authorization header is malformed; the Credential is mal-formed; expecting "<YOUR-AKID>/YYYYMMDD/REGION/SERVICE/aws4_request".

@mpenkov
Copy link
Collaborator

mpenkov commented Jul 19, 2023

Are you able to debug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants