Issue creating S3 Bucket Python

0 votes

The code I am trying to run as per the tutorials is:

import boto3

s3=boto3.resource('s3')

bucket_name="BucketMRaj"

try:

   response=s3.create_bucket(Bucket=bucket_name, CreateBucketConfiguration={'LocationConstraint':'us-east-2'})

print(response)

except Exception as error:

print(error)

Please help!

Jan 18 in Python by Suraj
38 views

Hello @Suraj, when you use

try:
    This follows an indentation
    Python strictly follows indentation 
except:
    Some Message

So the print statement that you are using should be within the try block. Just add suitable space and you are good to go.

Hello @Suraj, did you find the solution for the error you had? Please do share your feedback or any further error that you are facing.

1 answer to this question.

+1 vote

Hello @Suraj, There is an indentation issue,

>>> s3 = boto3.resource('s3')
>>> BucketName ="priayjdm1"
 >>> try:
...     response = s3.create_bucket(Bucket= BucketName)
...     print (response)
... except:
...     print ("works fine")
...
s3.Bucket(name='priayjdm1')
answered Jan 18 by Priyaj
• 56,200 points

Yet the issue occurs sir

Verify the indentation.

This is the indentation I am talking about.

Python follows indentation (instead of curly-braces for scope). Indentation is Tab Space on your keyboard. Wherever you need to give indentation, press the tab key on your keyboard. Please use proper indentations:

Related Questions In Python

0 votes
1 answer

Creating a matrix in Python

You can create arrays of any number ...READ MORE

answered Jun 19, 2018 in Python by Hamartia's Mask
• 1,580 points
30 views
0 votes
1 answer

Creating a new dict in Python

Call dict with no parameters new_dict = dict() or simply write new_dict ...READ MORE

answered Sep 17, 2018 in Python by Priyaj
• 56,200 points
26 views
0 votes
1 answer

Python: Issue with 'unexpected end of pattern'

I should start by stating that using ...READ MORE

answered Sep 24, 2018 in Python by Priyaj
• 56,200 points
82 views
0 votes
0 answers

Creating a mini language parser using Python

I'm planning to create a simple mini-language ...READ MORE

Dec 27, 2018 in Python by Anirudh
• 2,070 points
48 views
0 votes
1 answer

Boto3 S3, sort bucket by last modified

I tried the following method. Its not 100% ...READ MORE

answered Jun 4 in Python by SDeb
• 13,160 points
190 views
+1 vote
1 answer

Creating a range of dates in Python

Yes, you can do it as follows: import ...READ MORE

answered Jul 4 in Python by Wajiha
• 1,840 points
14 views
+3 votes
7 answers

How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

answered Mar 31, 2018 in Python by DareDev
• 6,810 points
112 views
0 votes
1 answer

Creating an empty list in Python

Here is how you can test which ...READ MORE

answered Aug 17, 2018 in Python by Priyaj
• 56,200 points
57 views
0 votes
1 answer

Python: Issue with 'unexpected end of pattern'

I should start by stating that using ...READ MORE

answered Sep 12, 2018 in Python by Priyaj
• 56,200 points
165 views