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

Usage example from README not works #59

Closed
spvkgn opened this issue Sep 16, 2019 · 7 comments · Fixed by #64
Closed

Usage example from README not works #59

spvkgn opened this issue Sep 16, 2019 · 7 comments · Fixed by #64
Labels
bug Something isn't working

Comments

@spvkgn
Copy link

spvkgn commented Sep 16, 2019

Am i do something wrong in this?

Python 3.6.8 (default, Aug 20 2019, 17:12:48) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import deezer
>>> client = deezer.Client()
>>> client.get_album(12).title
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Resource' object has no attribute 'title'
@browniebroke browniebroke added the bug Something isn't working label Sep 16, 2019
@browniebroke
Copy link
Owner

Thanks for the report, it looks like a bug! I think it worked at some point, but it's obviously not working anymore.

It's probably that the client methods aren't returning the proper classes, but the base Resource one. If you search and get relation from a Track this attribute is present, example:

> ipython
Python 3.6.8 (default, Jan 19 2019, 12:07:51)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import deezer

In [2]: client = deezer.Client()

In [3]: client.search('Discovery')[0]
Out[3]: <Track: One More Time>

In [4]: client.search('Discovery')[0].get_album()
Out[4]: <Album: Discovery>

In [5]: client.search('Discovery')[0].get_album().title
Out[5]: 'Discovery'

However, when trying to get the album directly, the type is a Resource, not an Album:

> ipython
Python 3.6.8 (default, Jan 19 2019, 12:07:51)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import deezer

In [2]: client = deezer.Client()

In [3]: client.get_album(12)
Out[3]: <deezer.resources.Resource object at 0x1032704e0>

There is a similar problem when trying to get other object types, like artists, track, etc...

@nrebena
Copy link
Contributor

nrebena commented Sep 25, 2019

The problem here is that the album 12 does not exist, and the method default to returning Ressource type.

https://api.deezer.com/album/12
{"error":{"type":"DataException","message":"no data","code":800}}

So this issue is more about error handling.
There are many ways one can go there:

  • This is not a bug, there is effectively no title to be returned. Let's change the README to an existing album id
  • Raise an error when getting an error from the API
  • Other...

@browniebroke
Copy link
Owner

Good find! Agree that the error should be made explicit, and raise an exception. Also we should not default to Resource type when no suitable resource type is found.

Also the README should be updated too I think.

@browniebroke
Copy link
Owner

@all-contributors please add @spvkgn for bug

@allcontributors
Copy link
Contributor

@browniebroke

I've put up a pull request to add @spvkgn! 🎉

@browniebroke
Copy link
Owner

@all-contributors please add @spvkgn for bug

@allcontributors
Copy link
Contributor

@browniebroke

I've put up a pull request to add @spvkgn! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants