question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Syntax Error when try to upload to S3

See original GitHub issue

I try to upload a file from Twilio URL to S3.

Here is the code I am using:

smart_open_s3_path = 's3://' + s3_bucket + '/' + s3_key_path
                        smart_open_s3_path_credential = 's3://' + aws_access_key + ':' + aws_SecretAccess_key + '@' + s3_bucket + '/' + s3_key_path
                        print(smart_open_s3_path_credential)

                        smart_url_object = smart_open.smart_open(media_url)
                        ##parsed_uri = smart_open.smart_open_lib._parse_uri(smart_open_s3_path_credential)
                        
                        with smart_open.smart_open(smart_open_s3_path_credential, 'wb') as fout:
                            for line in smart_url_object:
                                fout.write(line)

It always gives me syntax error:

invalid syntax (_base.py, line 414): SyntaxError
Traceback (most recent call last):
File "/var/task/index.py", line 118, in lambda_handler
with smart_open.smart_open(smart_open_s3_path_credential, 'wb') as fout:
File "/var/task/smart_open/smart_open_lib.py", line 231, in smart_open
binary, filename = _open_binary_stream(uri, binary_mode, **kw)
File "/var/task/smart_open/smart_open_lib.py", line 321, in _open_binary_stream
return _s3_open_uri(parsed_uri, mode, **kw), filename
File "/var/task/smart_open/smart_open_lib.py", line 383, in _s3_open_uri
return smart_open_s3.open(parsed_uri.bucket_id, parsed_uri.key_id, mode, **kwargs)
File "/var/task/smart_open/s3.py", line 73, in open
fileobj = BufferedOutputBase(bucket_id, key_id, min_part_size=s3_min_part_size, **kwargs)
File "/var/task/smart_open/s3.py", line 357, in __init__
s3 = session.resource('s3', **kwargs)
File "/var/task/boto3/session.py", line 389, in resource
aws_session_token=aws_session_token, config=config)
File "/var/task/boto3/session.py", line 263, in client
aws_session_token=aws_session_token, config=config)
File "/var/task/botocore/session.py", line 885, in create_client
client_config=config, api_version=api_version)
File "/var/task/botocore/client.py", line 70, in create_client
cls = self._create_client_class(service_name, service_model)
File "/var/task/botocore/client.py", line 95, in _create_client_class
base_classes=bases)
File "/var/task/botocore/hooks.py", line 227, in emit
return self._emit(event_name, kwargs)
File "/var/task/botocore/hooks.py", line 360, in _emit
aliased_event_name, kwargs, stop_on_response
File "/var/task/botocore/hooks.py", line 210, in _emit
response = handler(**kwargs)
File "/var/task/boto3/utils.py", line 61, in _handler
module = import_module(module)
File "/var/task/boto3/utils.py", line 52, in import_module
__import__(name)
File "/var/task/boto3/s3/inject.py", line 15, in <module>
from boto3.s3.transfer import create_transfer_manager
File "/var/task/boto3/s3/transfer.py", line 127, in <module>
from s3transfer.exceptions import RetriesExceededError as \
File "/var/task/s3transfer/__init__.py", line 134, in <module>
import concurrent.futures
File "/var/task/concurrent/futures/__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "/var/task/concurrent/futures/_base.py", line 414
raise exception_type, self._exception, self._traceback
^
SyntaxError: invalid syntax

The S3 URI should be correct since I follow the instruction, any clues?

Example S3 URI: s3://<access-key>:<secret-key>@omax-mis/twilio-messages-media/final/MEcd7c36e75f87dc6dd9e33702cdcd8fb6

Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
menshikh-ivcommented, Aug 30, 2018

@mpenkov let’s finish #204 and I’ll make bugfix release after it (weekend or next week)

0reactions
mpenkovcommented, Sep 2, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve errors uploading data to or downloading data ... - AWS
First, follow the steps below to run the SELECT INTO OUTFILE S3 or LOAD DATA FROM S3 commands using Amazon Aurora. If you...
Read more >
Syntax error: ' | ' unexpected in aws s3 upload script
Hi I tried to upload video on my aws s3 cloud account. I am using one script which is provided by aws. And...
Read more >
Error while uploading file to S3 bucket using Python boto3 ...
I am getting this error when I am trying to upload a file from my local computer to S3 bucket. Here is the...
Read more >
Re: 'Sync'ing Redshift to S3 causes a syntax error
Hi, Using the DSS engine to export data from Redshift to S3 is not recommended as it can be inefficient. The error suggests...
Read more >
How can I resolve errors I received while uploading data to or ...
... the Knowledge Center article with this video: https:// aws.amazon.com/premiumsupport/knowledge-center/amazon-aurora- upload -data- S3 / 0:00.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found