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

HTTP Error 429: Unknown Status Code #26

Open
justinsalamon opened this issue Oct 7, 2019 · 1 comment
Open

HTTP Error 429: Unknown Status Code #26

justinsalamon opened this issue Oct 7, 2019 · 1 comment

Comments

@justinsalamon
Copy link

Trying to retrieve metadata (in particular, the license) for multiple sounds on FreeSound, using the Python API with python 3.

Working example:

import freesound
client = freesound.FreesoundClient()
client.set_token(MYTOKEN, "token")
sound = client.get_sound(100852)

Error:

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
~/dev/miniconda3/envs/py35/lib/python3.5/site-packages/freesound.py in request(cls, uri, params, client, wrapper, method, data)
    241         try:
--> 242             f = urlopen(req)
    243         except HTTPError as e:

~/dev/miniconda3/envs/py35/lib/python3.5/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    162         opener = _opener
--> 163     return opener.open(url, data, timeout)
    164 

~/dev/miniconda3/envs/py35/lib/python3.5/urllib/request.py in open(self, fullurl, data, timeout)
    471             meth = getattr(processor, meth_name)
--> 472             response = meth(req, response)
    473 

~/dev/miniconda3/envs/py35/lib/python3.5/urllib/request.py in http_response(self, request, response)
    581             response = self.parent.error(
--> 582                 'http', request, response, code, msg, hdrs)
    583 

~/dev/miniconda3/envs/py35/lib/python3.5/urllib/request.py in error(self, proto, *args)
    509             args = (dict, 'default', 'http_error_default') + orig_args
--> 510             return self._call_chain(*args)
    511 

~/dev/miniconda3/envs/py35/lib/python3.5/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    443             func = getattr(handler, meth_name)
--> 444             result = func(*args)
    445             if result is not None:

~/dev/miniconda3/envs/py35/lib/python3.5/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
    589     def http_error_default(self, req, fp, code, msg, hdrs):
--> 590         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    591 

HTTPError: HTTP Error 429: Unknown Status Code

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-7-6d65a93aff27> in <module>()
----> 1 sound = client.get_sound(100852)

~/dev/miniconda3/envs/py35/lib/python3.5/site-packages/freesound.py in get_sound(self, sound_id, **params)
     88         """
     89         uri = URIS.uri(URIS.SOUND, sound_id)
---> 90         return FSRequest.request(uri, params, self, Sound)
     91 
     92     def text_search(self, **params):

~/dev/miniconda3/envs/py35/lib/python3.5/site-packages/freesound.py in request(cls, uri, params, client, wrapper, method, data)
    246                 return resp
    247             else:
--> 248                 raise FreesoundException(e.code, json.loads(resp))
    249         if py3:
    250             resp = f.read().decode("utf-8")

~/dev/miniconda3/envs/py35/lib/python3.5/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    310     if not isinstance(s, str):
    311         raise TypeError('the JSON object must be str, not {!r}'.format(
--> 312                             s.__class__.__name__))
    313     if s.startswith(u'\ufeff'):
    314         raise JSONDecodeError("Unexpected UTF-8 BOM (decode using utf-8-sig)",

TypeError: the JSON object must be str, not 'bytes'

Note: the code worked fine earlier for this file, but now it crashes. Maybe I'm being throttled and the response message breaks the API?

@ffont
Copy link
Member

ffont commented Oct 8, 2019

That's definitely because of throttling. We should make the python client handle that in a better way. In the meanwhile you can try/except HTTPError. Thanks for reporting @justinsalamon!

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

2 participants