Re: [boto-users] help for solving EC2ResponseError: 401 Unauthorized

2,076 views
Skip to first unread message

Mitchell Garnaat

unread,
Sep 26, 2012, 12:46:32 PM9/26/12
to boto-...@googlegroups.com
Hi -

It's definitely a credential problem.  The connect_ec2() method does not actually make a request to the service so the fact that you don't get an error there doesn't really tell us anything.

The AWS credentials can be confusing.  This blog entry is old but might still be useful:


Make sure you are putting the correct values (the AccessKeyID and SecretKey) in your boto file.  The error you are getting suggests that you have configured your boto config file correctly but you have the wrong value for the aws_access_key_id, the aws_secret_access_key or both.

Mitch

On Wed, Sep 26, 2012 at 9:18 AM, Veryel Hua <verye...@gmail.com> wrote:
Hi all,

I am a newbie to both aws and boto. I am trying to follow the boto document and tutorial online to set up my ec2 instance. But I cannot create instance or key pairs. I have not problem running conn=boto.connect_ec2() and my credentials are stored in ~/.boto. When I run conn.run_instance() or conn.create_key_pairs(), I get the following messages:

EC2ResponseError: EC2ResponseError: 401 Unauthorized
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>AuthFailure</Code><Message>AWS was not able to validate the provided access credentials</Message></Error></Errors><RequestID>59f6127b-d288-48b8-8442-e88e240a492f</RequestID></Response>

After hours of searching solution online, I couldn't find any answer. I am able to launch instances within my browser and I double checked my id and secret. Could anyone give me some help please? Thank you.

Cheers,
Veryel

--
You received this message because you are subscribed to the Google Groups "boto-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/boto-users/-/ufWoZvqT3igJ.
To post to this group, send email to boto-...@googlegroups.com.
To unsubscribe from this group, send email to boto-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/boto-users?hl=en.

Veryel Hua

unread,
Sep 26, 2012, 3:28:36 PM9/26/12
to boto-...@googlegroups.com, mi...@garnaat.com
Hi Mitch,

Thank you for reply. What you have said is absolutely right. If I explicitly specify my access key and secret key in the function of connect_ec2, I can create key pairs. I guess there's something wrong with my .boto configure file. I check the value and it's the same with the one I used explicitly in connect_ec2. It's like this:

[Credentials]
aws_access_key_id = G2PGY2XOWGU2AAKIAIAQ
aws_secret_access_key = Y14kdkWPHhQMekQJtAWN93GrJSibrZfsE5nmsIvV

The key values are not real one. But I just want to know if there's any format problem. Thanks!

Cheers,
Veryel

Adrian Klaver

unread,
Sep 26, 2012, 3:37:28 PM9/26/12
to boto-...@googlegroups.com, Veryel Hua, mi...@garnaat.com
On 09/26/2012 12:28 PM, Veryel Hua wrote:
> Hi Mitch,
>
> Thank you for reply. What you have said is absolutely right. If I
> explicitly specify my access key and secret key in the function of
> connect_ec2, I can create key pairs. I guess there's something wrong
> with my .boto configure file. I check the value and it's the same with
> the one I used explicitly in connect_ec2. It's like this:
>
> [Credentials]
> aws_access_key_id = G2PGY2XOWGU2AAKIAIAQ
> aws_secret_access_key = Y14kdkWPHhQMekQJtAWN93GrJSibrZfsE5nmsIvV
>
> The key values are not real one. But I just want to know if there's any
> format problem. Thanks!

Is the file named boto.cfg and is it in the locations specified here?:
http://code.google.com/p/boto/wiki/BotoConfig

If the file is named correctly and is in the location(s) can the user
you run the script as get to and use that file?

>
> Cheers,
> Veryel
>


--
Adrian Klaver
adrian...@gmail.com

Veryel Hua

unread,
Sep 26, 2012, 3:48:05 PM9/26/12
to Adrian Klaver, boto-...@googlegroups.com, mi...@garnaat.com
Hi Adrian,

The file is named .boto and it's placed in my home folder. I did this by following the exact page you linked. Should I change its name to boto.cfg and make folder .boto in home folder? 

Cheers,
Veryel

Adrian Klaver

unread,
Sep 26, 2012, 3:51:37 PM9/26/12
to Veryel Hua, boto-...@googlegroups.com, mi...@garnaat.com
On 09/26/2012 12:48 PM, Veryel Hua wrote:
> Hi Adrian,
>
> The file is named .boto and it's placed in my home folder. I did this by
> following the exact page you linked. Should I change its name to
> boto.cfg and make folder .boto in home folder?

My mistake, you are correct, boto.cfg is for the /etc version. .boto for
the ~/ version. My second question still holds, is the user you are
running the script as have rights to that file?

Veryel Hua

unread,
Sep 26, 2012, 4:06:57 PM9/26/12
to Adrian Klaver, boto-...@googlegroups.com, mi...@garnaat.com
Hi Adrian,

Yes, I have the user right to read and write the file. It's my home folder. 

Cheers,
Veryel

Adrian Klaver

unread,
Sep 26, 2012, 4:17:02 PM9/26/12
to Veryel Hua, boto-...@googlegroups.com, mi...@garnaat.com
On 09/26/2012 01:06 PM, Veryel Hua wrote:
> Hi Adrian,
>
> Yes, I have the user right to read and write the file. It's my home folder.

And that is where you are running the script?

The other option is, per Mitch, are you sure you do not have the
access_key and secret_access_key values reversed?

Mitchell Garnaat

unread,
Sep 26, 2012, 4:21:38 PM9/26/12
to Adrian Klaver, Veryel Hua, boto-...@googlegroups.com
It's definitely finding your boto config file.  If it couldn't find any credentials, you would get a different error about "check your credentials".  So, it's finding them but they are somehow corrupted or mistyped or something.

As a sanity check, try something like this:

>>> import boto
>>> boto.config.get('Credentials', 'aws_access_key_id')
<should print out your access key>
>>> boto.config.get('Credentials', 'aws_secret_access_key')
<should print out your secret key>

And compare those values, very carefully!, to your known good credentials.

Mitch

Veryel Hua

unread,
Sep 26, 2012, 5:27:40 PM9/26/12
to Mitchell Garnaat, Adrian Klaver, boto-...@googlegroups.com
Hi Mitch & Adrian,

I ran the functions:
>>> boto.config.get('Credentials', 'aws_access_key_id')
<should print out your access key>
>>> boto.config.get('Credentials', 'aws_secret_access_key')
<should print out your secret key>

When I used the output from these two calls to be key parameters in connect_ec2 function, it works. However, it still doesn't work if I only rely on the configuration file. I am using ipython for all of these operation and all are in my home folder.

Cheers,
Veryel

Adrian Klaver

unread,
Sep 26, 2012, 5:51:03 PM9/26/12
to Veryel Hua, Mitchell Garnaat, boto-...@googlegroups.com
On 09/26/2012 02:27 PM, Veryel Hua wrote:
> Hi Mitch & Adrian,
>
> I ran the functions:
> >>> boto.config.get('Credentials', 'aws_access_key_id')
> <should print out your access key>
> >>> boto.config.get('Credentials', 'aws_secret_access_key')
> <should print out your secret key>
>
> When I used the output from these two calls to be key parameters in
> connect_ec2 function, it works. However, it still doesn't work if I only
> rely on the configuration file. I am using ipython for all of these
> operation and all are in my home folder.

The IPython console or notebook?
I have noticed screwy behavior when using the notebook.
What happens when you run from the Python shell or run in a stand alone
script?

Veryel Hua

unread,
Sep 26, 2012, 10:37:44 PM9/26/12
to Adrian Klaver, Mitchell Garnaat, boto-...@googlegroups.com
Hi Adrian,

I ran it within ipython console. And the error also occurs when I use python console. However, I just tried boot at home, it works on my ubuntu laptop. I was using Mac when I encountered this problem. Thank you.

Cheers,
Veryel

Adrian Klaver

unread,
Sep 26, 2012, 10:40:44 PM9/26/12
to Veryel Hua, Mitchell Garnaat, boto-...@googlegroups.com
On 09/26/2012 07:37 PM, Veryel Hua wrote:
> Hi Adrian,
>
> I ran it within ipython console. And the error also occurs when I use
> python console. However, I just tried boot at home, it works on my
> ubuntu laptop. I was using Mac when I encountered this problem. Thank you.

It has been noted on the Postgres lists that Macs have some unique
locale/encoding behavior. Could be you are being bit by this.
Reply all
Reply to author
Forward
0 new messages