sefakilic / goodreads

:snake: Python wrapper for Goodreads API :books:
262 stars 100 forks source link

Reviews bug #2

Open arjunblj opened 9 years ago

arjunblj commented 9 years ago

Hey man – quick q. When I try to access reviews (after authentication), this breaks (error below). I wasn't able to figure out where it was breaking at a quick glance but if you have any theories, I'd be happy to fix it and write some more thorough tests for it.

screenshot 2015-04-15 15 38 18

sefakilic commented 9 years ago

Does the authenticated user have any reviews? If not, the API might be returning something unexpected.

arjunblj commented 9 years ago

Yes, the user has many reviews, so I'm trying to figure out what the issue is. (side note: for contributers, how do I access apikey.py? I've tried running the command in the Travis config file but it's not working.)

sefakilic commented 9 years ago

apikey.py stores API developer key and secret. To be specific it has

key = 'foo' secret = 'bar' oauth_access_token = 'baz' oauth_access_token_secret = 'qux'

The last two are OAuth key and secrets that are used in client.authenticate function.

You can create the file (under goodreads/goodreads directory) to run tests with nose.

nasimsonboli commented 8 years ago

Hi Sefa, Actually, I'm having the same problem as Arjun. I made sure that the key,secret pair is different from oauth token, secret pair. I'm running your package in Win7-64bit. When I try to run this code, it gives me the same error. res = gc.session.get('shelf/list.xml', params={'page':'1', 'user_id':'1'}) error

Any hint will be helpful, Thank you,

karsalfrink commented 8 years ago

Same here, when I try to do reviews = user.reviews() I get the following error:

Traceback (most recent call last):
  File "/Users/Kars/Projects/goodreads-weighted-average-rating/list.py", line 12, in <module>
    reviews = user.reviews()
  File "/Users/Kars/Virtualenvs/goodreads-weighted-average-rating/lib/python2.7/site-packages/goodreads/user.py", line 66, in reviews
    {'v': 2, 'id': self.gid, 'page': page})
  File "/Users/Kars/Virtualenvs/goodreads-weighted-average-rating/lib/python2.7/site-packages/goodreads/session.py", line 54, in get
    return xmltodict.parse(resp.content)['GoodreadsResponse']
  File "/Users/Kars/Virtualenvs/goodreads-weighted-average-rating/lib/python2.7/site-packages/xmltodict.py", line 311, in parse
    parser.Parse(xml_input, True)
xml.parsers.expat.ExpatError: syntax error: line 1, column 0
[Finished in 2.1s with exit code 1]

A fix would be most welcome.

karsalfrink commented 8 years ago

Following up on my previous comment. I poked around a little bit more and got this to work:

res = gc.session.get('review/list?v=2', params={'id':user_id, 'shelf':'to-read', 'key':developer_key})

My guess is it has something to do with the fact that user.reviews() uses self._client.session.get whereas user.shelves() (which does work for me) uses self._client.request. Something about a developer key not getting passed or something? I don't have a session? I don't know. Kind of out of my depth here.

karsalfrink commented 8 years ago

Okay, so if I change your code like so (explicitly passing the client_key), it works:

    def reviews(self, page=1):
        """Get all books and reviews on user's shelves"""
        resp = self._client.session.get("/review/list.xml",
                                        {'v': 2, 'id': self.gid, 'page': page, 'key': self._client.client_key})
        return [review.GoodreadsReview(r) for r in resp['reviews']['review']]

No idea if this is an acceptable fix, just thought I'd share.