cenkalti / putio.py

A python wrapper for put.io APIv2
http://put.io
MIT License
72 stars 41 forks source link

Server API response seems to have changed, successful file upload raises KeyError #14

Closed datashaman closed 8 years ago

datashaman commented 8 years ago

I noticed my watcher went crazy last night because of an unexpected response from the server, which caused it to go into a loop and upload the same torrent over and over. This could have resulted in a massive amount of bandwidth used if the files had been downloaded again as well, so the bug seems pretty serious to me.

The thing that triggered the error was the post-request status check:

if response['status'] == 'ERROR':
    ...

If there is no error, the key status does not exist, which raises a KeyError: 'status'.

In the case of a file upload, which is what I was doing, the response was:

{u'transfer': { u'status': 'IN_QUEUE', ... }}

There is a status key inside transfer, but the top-level one is missing.

This only started happening last night. Server change?

datashaman commented 8 years ago

According to the API docs, the file upload response should have a top-level status property with value OK when successful. - https://put.io/v2/docs/files.html#upload

datashaman commented 8 years ago

Also, I recall there was some measure on the server-side for refusing to add a torrent if it was already in the transfer list? If so, that is not happening. I could be wrong about this part. :)

datashaman commented 8 years ago

As a workaround, I've changed the above line to read:

if response.get('status') == 'ERROR':
    ...
cenkalti commented 8 years ago

Thank you very much for noticing this. We have made a change yesterday on server side. This is definitely a bug that breaks the API. I have just deployed the fix now. Can you confirm that it is fixed?

The API returns status=OK on successful responses.

And for transfer that already exists a response with status code 400 must be returned and body is like: {"status": "ERROR", "status_code": 400, "error_type": "TransferAddLimitReached", ...}

datashaman commented 8 years ago

Hi there, just confirmed the status of OK is now there. :)

On 24 February 2016 at 09:22, Cenk Altı notifications@github.com wrote:

Thank you very much for noticing this. We have made a change yesterday on server side. This is definitely a bug that breaks the API. I have just deployed the fix now. Can you confirm that it is fixed?

The API returns status=OK on successful responses.

And for transfer that already exists a response with status code 400 must be returned and body is like: {"status": "ERROR", "status_code": 400, "error_type": "TransferAddLimitReached", ...}

— Reply to this email directly or view it on GitHub https://github.com/cenkalti/putio.py/issues/14#issuecomment-188116937.