Mendeley / mendeley-api-python-example

Apache License 2.0
80 stars 28 forks source link

KeyError: 'state' on mendeley.start_authorization_code_flow(state=session['state']) #3

Open smidm opened 9 years ago

smidm commented 9 years ago
127.0.0.1 - - [19/Feb/2015 12:50:13] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [19/Feb/2015 12:50:16] "GET /oauth?state=.....&code=..... HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/home/matej/.virtualenvs/mendeley-api-python-example/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/matej/.virtualenvs/mendeley-api-python-example/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/home/matej/.virtualenvs/mendeley-api-python-example/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/matej/.virtualenvs/mendeley-api-python-example/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/matej/.virtualenvs/mendeley-api-python-example/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/matej/.virtualenvs/mendeley-api-python-example/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/matej/.virtualenvs/mendeley-api-python-example/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/matej/.virtualenvs/mendeley-api-python-example/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/..../mendeley-api-python-example/mendeley-example.py", line 33, in auth_return
    auth = mendeley.start_authorization_code_flow(state=session['state'])
  File "/home/matej/.virtualenvs/mendeley-api-python-example/lib/python2.7/site-packages/werkzeug/local.py", line 368, in <lambda>
    __getitem__ = lambda x, i: x._get_current_object()[i]
KeyError: 'state'

My installed modules:

(mendeley-api-python-example) ↪ pip freeze
-f /home/matej/.pip/wheels
Flask==0.10.1
Jinja2==2.7.3
MarkupSafe==0.23
PyYAML==3.11
Werkzeug==0.10
argparse==1.2.1
arrow==0.5.0
certifi==14.05.14
future==0.14.3
itsdangerous==0.24
memoized-property==1.0.2
mendeley==0.3.0
oauthlib==0.7.2
python-dateutil==2.4.0
requests==2.5.1
requests-oauthlib==0.4.2
six==1.9.0
wheel==0.24.0
wsgiref==0.1.2
akselx commented 9 years ago

I got the same issue, Ubuntu 14.04, python 2.7.

kjgarza commented 9 years ago

I have the same issue, any solution yet?

kjgarza commented 9 years ago

Curly brackets are not required!!!!! clientId: 1111 clientSecret: nddfdf7979df

silpol commented 9 years ago

@kjgarza curly brackets cause issue #2 Once I have removed them, I got towards login and after login I bumped into issue described in this report, literally (minus hashes and other possible ephemerals).

silpol commented 9 years ago

@smidm , @akselx and @kjgarza - have you managed to get down the bottom of this bug? or do we have to disturb @MendeleyStack to help us?

Joyce-Stack commented 9 years ago

Hello,

I'm trying to find someone with Ubuntu installed in our team. Stand by.

Joyce-Stack commented 9 years ago

I am currently looking into this but I need to fix this issue first as I can't proceed until then - https://github.com/Mendeley/mendeley-api-python-example/issues/4

Joyce-Stack commented 9 years ago

I have had colleagues run this example and get successful responses using:-

I re-cloned this project on my Macbook and was able to rerun it successfully. Also, I went to the developer portal and regenerated my secret.

Can you try and do a pip uninstall all - http://stackoverflow.com/questions/11248073/what-is-the-easiest-way-to-remove-all-packages-installed-by-pip

livia-b commented 8 years ago

I also came across this problem, and somehow it worked after regenerating the secret, clearing cookies, changing browser ... hope that helps (mac, python 2.7, chrome and firefox)

StankoPalko commented 8 years ago

This is due to redirect url. If you are running locally like I am your site runs on: http://127.0.0.1:5000/ but your redirect URL is set to http://localhost:5000/oauth which are two sites in terms of cookies so cookies can't be found and hence the key error. Change it to http://127.0.0.1:5000/oauth

michaelplews commented 8 years ago

@StankoPalko do you mean change the URI to http://1270.0.1:5000/oauth in the mendeley-example.py file? or on dev.mendeley.com?

smidm commented 7 years ago

This solved the issue for me: