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, 2019 in Python by Suraj
1,372 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, 2019 by Priyaj
• 58,020 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

How to ignore Headers in S3 bucket CSV file using python?

Hi@durgaraju, You can fetch only the body part. ...READ MORE

answered Dec 29, 2020 in Python by MD
• 95,460 points
2,185 views
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
858 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
• 58,020 points
563 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,090 points
966 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, 2019 in Python by SDeb
• 13,300 points
15,618 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, 2019 in Python by Wajiha
• 1,960 points
1,448 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
• 58,020 points
1,073 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
• 58,020 points
2,627 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP