Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to authenticate. 403 code #45

Closed
commadelimited opened this issue Feb 14, 2013 · 23 comments
Closed

Unable to authenticate. 403 code #45

commadelimited opened this issue Feb 14, 2013 · 23 comments

Comments

@commadelimited
Copy link
Contributor

Trying to login to test this library out and I'm getting an error. I've made sure to install gspread. I created a single python file, test.py. My code is as simple as it gets:

import gspread

# Login with your Google account
gc = gspread.login('<username>', '<password>')

Yet when I run this via the terminal python test.py I get the following error:

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    gc = gspread.login('<username>', '<password>')
  File "/Library/Python/2.7/site-packages/gspread/client.py", line 278, in login
    client.login()
  File "/Library/Python/2.7/site-packages/gspread/client.py", line 99, in login
    raise AuthenticationError("Unable to authenticate. %s code" % ex.code)
gspread.exceptions.AuthenticationError: Unable to authenticate. 403 code

I confirmed that my login credentials were correct by logging out of Google docs, then logging back in, then copying and pasting the u/p into test.py and still nothing. Any suggestions?

@commadelimited
Copy link
Contributor Author

btw. I'm using Python 2.7.1

@commadelimited
Copy link
Contributor Author

It looks like the primary issue might be that your authentication schema is incorrect. in client.py, line 31-32 look like this:

AUTH_SERVER = 'https://www.google.com'
SPREADSHEETS_SERVER = 'spreadsheets.google.com'

While signing into a Google property takes me to this URL:

https://accounts.google.com/ServiceLogin

@commadelimited
Copy link
Contributor Author

Or maybe not. I tried the official Google Python library and it gives me the same error. I don't get it. I've logged in successfully, then copied/pasted my credentials into the login method and still no joy. Is my pw supposed to be plain text in the login method call?

@commadelimited
Copy link
Contributor Author

Looks like this was an issue with Google's two factor authorization. I'm submitting a pull request to update the docs for other's benefit.

@commadelimited
Copy link
Contributor Author

#46

@burnash
Copy link
Owner

burnash commented Feb 19, 2013

Great, many thanks for discovering this!

@commadelimited
Copy link
Contributor Author

No problem. Your library works great.

@burnash
Copy link
Owner

burnash commented Feb 20, 2013

Thank you

@idcrook
Copy link

idcrook commented May 7, 2013

gdata does seem to work for me is I instead use an application-specific password from the two-factor authentication settings page...

@flyingfoxlee
Copy link

It's happens to me too, but in my case, it was caused by login to google from a suspicious ip. so I login the online account and find google warn me with the message "We detected activity on your Google Account from a location you don't usually sign in from. Review the information below and tell us whether you recognize this activity". I can recognize that activity and it works. Thanks for the great library~

@burnash
Copy link
Owner

burnash commented Jun 10, 2013

Thanks for sharing this!

@tcorbettclark
Copy link

gspread works fine for me with two factor authentication. You just need to create and use an application-specific password:

https://accounts.google.com/b/0/IssuedAuthSubTokens?hl=en_GB

Your username is your email as usual.

It is better this way anyway since your main user password is not used anywhere near your code, and the application specific password can be discarded/revoked independently.

@burnash
Copy link
Owner

burnash commented Sep 28, 2013

@tcorbettclark Thanks for the finding!

@jwal
Copy link

jwal commented Dec 6, 2013

You can also get a 403 error when Google thinks that your login is suspicious. I was logging in using a dedicated robot Google account from a Jenkins server hosted on Amazon EC2. I had to do two things:

I hope this helps.

@multivoxmuse
Copy link

I came here looking for exactly the answer @tcorbettclark gave. It was my 2-factor auth. I had also been wondering how the heck I could get away from using my personal password in my script anyway.

Thanks!

@abhinavabcd
Copy link

@jwal .. thanks , you comment saved my time.

@fiatjaf
Copy link

fiatjaf commented Aug 27, 2014

@jwal saves lifes.

@sanderjo
Copy link
Contributor

To confirm & FYI:

I had the same "gspread.exceptions.AuthenticationError: Unable to authenticate. 403 code"

After the failed gspread logon, I immediately received a mail from Google/Gmail (no-reply@accounts.google.com) in my gmail about a suspicous login attempt. I confirmed the login request was OK, and went to https://www.google.com/settings/security/lesssecureapps to accept lower-security apps to access my gmail account.

After that, the gspread login went OK.

PS: @burnash What a fantastic piece of software gspread is. Thank you very much!

@grillazz
Copy link

thx @sanderjo

@burnash
Copy link
Owner

burnash commented Nov 12, 2014

@sanderjo Thanks for the feedback 👍

@Glench
Copy link

Glench commented Jan 13, 2015

@jwal Thanks for the helpful comment! The second step worked for me.

@sanderjo
Copy link
Contributor

And one more update:

I got the 403 with another account I just created, and clicking on the URL https://www.google.com/settings/security/lesssecureapps did not solve it.

More digging revealed I had to also go to this URL: https://accounts.google.com/DisplayUnlockCaptcha, and after that I could use gspread.

FWIW: I put some extra logging into line 112 of gspread/client.py and that revealed this:

gspread.exceptions.AuthenticationError: Unable to authenticate. 403 code with content 
Error=BadAuthentication
Url=https://www.google.com/accounts/ContinueSignIn?blabla
Info=WebLoginRequired

Googling "Info=WebLoginRequired" led me to that URL https://accounts.google.com/DisplayUnlockCaptcha

HTH

@gluefish
Copy link

gluefish commented Jan 6, 2016

Please update your GSpread API Reference.

The GSpread API Reference still says:

gspread.login(email, password)
Login to Google API using email and password.
This is a shortcut function which instantiates Client and performs login right away.
Returns: Client instance.

But, when I run it that way it says:
Warning:
ClientLogin is deprecated:
https://developers.google.com/identity/protocols/AuthForInstalledApps?csw=1
Authorization with email and password will stop working on April 20, 2015.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests