Mendeley / mendeley-python-sdk

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

Auth throws value error on 504 #12

Open bettsmatt opened 8 years ago

bettsmatt commented 8 years ago

I believe there is a bug in your auth code that raises a value error when encountering a 504 as content type if not set on the 504 response.

mendeley/auth.py in handle_text_response at line 12

def handle_text_response(rsp):
    if rsp.headers['content-type'] == 'text/plain':
        rsp._content = bytes(json.dumps({'error': 'invalid_client', 'error_description': rsp.text}), rsp.encoding)
        rsp.headers['content-type'] = 'application/json'
    return rsp

rsp.headers['content-type'] == 'text/plain': Raises a value error. Can you please fix this so the app using the API can choose how to handle the 504 response.

We are using version 0.3.2.

bettsmatt commented 8 years ago

Are you going to fix this?

Joyce-Stack commented 8 years ago

I'm happy for you to create a pull request and make a fix?

We have now added instructions for this on the README page including a build monitor.

Apologies for letting this slip.

bettsmatt commented 8 years ago

Given this is the Mendeley API I would prefer if you fixed it. It is still an issue, this is our current work around.

 try:
     session = MendeleyAPIFinder.__start_mendeley_session()
 except KeyError as e:
     pass
 else:
     # Do stuff with the session.
Joyce-Stack commented 8 years ago

Thank you for your contribution. We have recently added a Travis Build to the SDK and we do have tests so I encourage you to to create pull requests and ensure nobody else suffers ;-)

I do endeavour to try and fix these issues but I'm not always the best person as my Python is not very strong.

I'll take a look and run some tests locally. Thank you.