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

requests.exceptions.HTTPError with GoogleOAuth2 #1095

Open
egorov-aleksey opened this issue Apr 4, 2017 · 3 comments
Open

requests.exceptions.HTTPError with GoogleOAuth2 #1095

egorov-aleksey opened this issue Apr 4, 2017 · 3 comments

Comments

@egorov-aleksey
Copy link

egorov-aleksey commented Apr 4, 2017

I have Flask app. When I try authenticate with Google I've got error:

requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://accounts.google.com/o/oauth2/token
Traceback:

127.0.0.1 - - [04/Apr/2017 16:06:51] "GET /login/google-oauth2/?next=%2F HTTP/1.1" 302 -
127.0.0.1 - - [04/Apr/2017 16:07:04] "GET /complete/google-oauth2/?state=iUcmi1fyzXKoyhiQGMEVskFfSp1G9O3F&code=4/ZIS2te9WsomtVHYHak884Tz88eeZRahYMDj35NR6KTo&authuser=0&session_state=f9247b499ccf7eb774bb453c1a0348b4de917afb..6299&prompt=consent HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/project/env/lib/python3.4/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/project/env/lib/python3.4/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/project/env/lib/python3.4/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/project/env/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/project/env/lib/python3.4/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/project/env/lib/python3.4/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/project/env/lib/python3.4/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/project/env/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/project/env/lib/python3.4/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/project/env/lib/python3.4/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/project/env/lib/python3.4/site-packages/social_flask/utils.py", line 43, in wrapper
    return func(backend, *args, **kwargs)
  File "/project/env/lib/python3.4/site-packages/social_flask/routes.py", line 23, in complete
    *args, **kwargs)
  File "/project/env/lib/python3.4/site-packages/social_core/actions.py", line 41, in do_complete
    user = backend.complete(user=user, *args, **kwargs)
  File "/project/env/lib/python3.4/site-packages/social_core/backends/base.py", line 39, in complete
    return self.auth_complete(*args, **kwargs)
  File "/project/env/lib/python3.4/site-packages/social_core/utils.py", line 253, in wrapper
    return func(*args, **kwargs)
  File "/project/env/lib/python3.4/site-packages/social_core/backends/oauth.py", line 394, in auth_complete
    method=self.ACCESS_TOKEN_METHOD
  File "/project/env/lib/python3.4/site-packages/social_core/backends/oauth.py", line 372, in request_access_token
    return self.get_json(*args, **kwargs)
  File "/project/env/lib/python3.4/site-packages/social_core/backends/base.py", line 227, in get_json
    return self.request(url, *args, **kwargs).json()
  File "/project/env/lib/python3.4/site-packages/social_core/backends/base.py", line 223, in request
    response.raise_for_status()
  File "/project/env/lib/python3.4/site-packages/requests/models.py", line 909, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://accounts.google.com/o/oauth2/token

pip freeze:

alembic==0.9.1
click==6.7
defusedxml==0.5.0
Flask==0.12.1
Flask-Cors==3.0.2
Flask-Fixtures==0.3.7
Flask-Login==0.4.0
Flask-Migrate==2.0.3
Flask-Script==2.0.5
Flask-SQLAlchemy==2.2
future==0.16.0
itsdangerous==0.24
Jinja2==2.9.6
Mako==1.0.6
MarkupSafe==1.0
oauthlib==2.0.2
psycopg2==2.7.1
pycryptodomex==3.4.5
pyjwkest==1.3.2
PyJWT==1.4.2
python-editor==1.0.3
python-social-auth==0.3.6
python3-openid==3.1.0
requests==2.13.0
requests-oauthlib==0.8.0
six==1.10.0
social-auth-app-flask==1.0.0
social-auth-app-flask-sqlalchemy==1.0.1
social-auth-core==1.2.0
social-auth-storage-sqlalchemy==1.0.1
SQLAlchemy==1.1.8
Werkzeug==0.12.1

What I'm doing wrong?

@goozmake
Copy link

goozmake commented Apr 4, 2017

I have same error!

@nh-99
Copy link

nh-99 commented Apr 15, 2017

What worked for me was to enable the Google+ API on the Google Developer Console.

@randyyuan
Copy link

randyyuan commented Jun 1, 2017

I had the same error with both Google+ API and Gmail API enabled on Google Developer Console

Update: I think my problem was due to expired tokens on the app's side.

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

4 participants