Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Uploading a file to s3
#1
I am trying the below to upload a file to s3. I a, using python 2.7.

import boto3
from botocore.exceptions import NoCredentialsError
ACCESS_KEY = 'xxxxxxxxxxxxxx'
SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
def upload_to_aws(local_file, bucket, s3_file):s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY,aws_secret_access_key=SECRET_KEY)
#try:s3.upload_file(local_file, bucket, s3_file)
upload_to_aws('C:\Users\test_2_fields.csv', 'test-bukcet-aws', '/tmpload/test_2_fields.csv')

I am running into syntax error. can you please suggest what's wrong
Larz60+ write Nov-25-2020, 11:44 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Also please fix indentation errors.
Reply
#2
(Nov-25-2020, 08:42 PM)pisike Wrote: I am trying the below to upload a file to s3. I a, using python 2.7.

import boto3
from botocore.exceptions import NoCredentialsError
ACCESS_KEY = 'xxxxxxxxxxxxxx'
SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
def upload_to_aws(local_file, bucket, s3_file):s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY,aws_secret_access_key=SECRET_KEY)
#try:s3.upload_file(local_file, bucket, s3_file)
upload_to_aws('C:\Users\test_2_fields.csv', 'test-bukcet-aws', '/tmpload/test_2_fields.csv')

I am running into syntax error. can you please suggest what's wrong

I am getting syntax error. This is the whole code I have
Reply
#3
Use python tags around your code (or the python button above the editor). Can't see the indentation otherwise. You haven't shown us the (complete) error message either

You shouldn't have anything on the same line after the colon on the "def" line. Looks like two lines got joined that shouldn't be.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 447 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  Uploading files to NAS from Raspberry PI using python zazas321 0 2,465 Sep-07-2020, 09:02 AM
Last Post: zazas321
  Uploading CSV Files to Google drive in a specified folder prashant8530 1 3,183 Sep-30-2017, 10:58 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020