Mendeley / mendeley-python-sdk

Python SDK for the Mendeley API.
Apache License 2.0
119 stars 59 forks source link

Authentication Timeout error #21

Open tesserata opened 6 years ago

tesserata commented 6 years ago

I'm trying to use start_authorization_code_flow() to authorise (I need to have access to my documents)

The code is the following:

from mendeley import Mendeley
from requests import post, get, session

secret = '<secret>'
app_id = '<id'>
redirect_uri = 'mendeley.com'

sdk = Mendeley(app_id, secret, redirect_uri)
auth = sdk.start_authorization_code_flow()
credentials = {'username': '<username>', 'password': '<password>'}

s = session()
login_url = auth.get_login_url()
login = s.post(login_url, credentials)

Then s.post(login_url, credentials) returns a timeout error. Same if I just copy the login url and try to manually log in with browser. However, if I'm trying to use start_client_credentials_flow() method, everything is well.

Traceback follows

<ipython-input-73-86dcfcea52de> in <module>()
----> 1 login = s.post(login_url, credentials)
/home/belyaevadg/anaconda3/lib/python3.6/site-packages/requests/sessions.py in post(self, url, data, json, **kwargs)
    502         """
    503 
--> 504         return self.request('POST', url, data=data, json=json, **kwargs)
    505 
    506     def put(self, url, data=None, **kwargs):

/home/belyaevadg/anaconda3/lib/python3.6/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    459         }
    460         send_kwargs.update(settings)
--> 461         resp = self.send(prep, **send_kwargs)
    462 
    463         return resp

/home/belyaevadg/anaconda3/lib/python3.6/site-packages/requests/sessions.py in send(self, request, **kwargs)
    597 
    598         # Resolve redirects if allowed.
--> 599         history = [resp for resp in gen] if allow_redirects else []
    600 
    601         # Shuffle things around if there's history.

/home/belyaevadg/anaconda3/lib/python3.6/site-packages/requests/sessions.py in <listcomp>(.0)
    597 
    598         # Resolve redirects if allowed.
--> 599         history = [resp for resp in gen] if allow_redirects else []
    600 
    601         # Shuffle things around if there's history.

/home/belyaevadg/anaconda3/lib/python3.6/site-packages/requests/sessions.py in resolve_redirects(self, resp, req, stream, timeout, verify, cert, proxies)
    190                 cert=cert,
    191                 proxies=proxies,
--> 192                 allow_redirects=False,
    193             )
    194 

/home/belyaevadg/anaconda3/lib/python3.6/site-packages/requests/sessions.py in send(self, request, **kwargs)
    571 
    572         # Send the request
--> 573         r = adapter.send(request, **kwargs)
    574 
    575         # Total elapsed time of the request (approximately)

/home/belyaevadg/anaconda3/lib/python3.6/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    413 
    414         except (ProtocolError, socket.error) as err:
--> 415             raise ConnectionError(err, request=request)
    416 
    417         except MaxRetryError as e:

ConnectionError: ('Connection aborted.', TimeoutError(110, 'Connection timed out'))

Any help would be appreciated!