2

I am trying to upload a file in S3 using boto3.I tried below code.

 import boto3
 s3 = boto3.resource('s3')
 buck_name = s3.create_bucket(Bucket='trubuckboto')

s3.Object('trubuckboto','tlearn.txt').upload_file(
      Filename='G:\tlearn.txt')

My bucket creation is successfull but i am not able to upload file from location G:\tlearn.txt inside that bucket.Below is the error i am getting

return os.stat(filename).st_size OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'G:\tlearn.txt'

Can someone suggest what i am missing here ?

1 Answer 1

3

In Python strings, the backslash "\" is a special character, also called the "escape" character. If you want a literal backslash then you need to escape the escape character, for example G:\\tlearn.txt:

import boto3
s3 = boto3.resource('s3')
# buck_name = s3.create_bucket(Bucket='trubuckboto')

s3.Object('trubuckboto', 'tlearn.txt').upload_file(
    Filename='G:\\tlearn.txt')
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I will try this in evening and will update you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.