discogs / discogs_client

DEPRECATED - Official Python Client for the Discogs API
http://www.discogs.com/developers
Other
479 stars 132 forks source link

Non-ASCII searches fail because python-oauth2 is broken #40

Closed sampsyo closed 9 years ago

sampsyo commented 10 years ago

Searching for a non-ASCII term causes this error:

>>> import discogs_client
>>> c = discogs_client.Client('user_agent', 'bogus_key', 'bogus_secret')
>>> c.search(u'caf\xe9'.encode('utf8')).page(1)
Traceback (most recent call last):
[ ... snip ... ]
  File "/usr/local/lib/python2.7/site-packages/oauth2/__init__.py", line 442, in to_url
    urllib.urlencode(query, True), fragment)
  File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1357, in urlencode
    l.append(k + '=' + quote_plus(str(elt)))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-4: ordinal not in range(128)

This is due to a known bug in python-oauth2: https://github.com/simplegeo/python-oauth2/issues/154. That library, unfortunately, appears to be abandoned: the last commit was in 2011 (c.f. this lament over the sorry state of Python OAuth libraries).

It's worth noting that this was not an issue when sending non-ASCII requests without OAuth authentication because they don't go through the broken library. This has only come up recently because the search API now requires authentication, so we're now these previously-working requests are now hitting this bug.

As unattractive as it seems, I think the only solution may be to move to a more modern OAuth library. Personally, I've had success with rauth.

rodneykeeling commented 10 years ago

Yikes, yeah this is definitely an issue. Replacing python-oauth2 won't be a quick task, but I agree that it must be done at some point. Thanks for the suggestions; I'll investigate this a bit more.

Cheers, Rodney

sampsyo commented 10 years ago

Cool! I'm happy to help if I can (maybe I'll get around to throwing together an rauth patch for your consideration, for example).

Also, did you mean to close this issue? I know I often hit the wrong button under the comment box. :smiley:

rodneykeeling commented 10 years ago

That would be awesome! And no, I'll reopen it. haha

vindarel commented 9 years ago

Hello there ! I'm looking forward to using the discogs client. Any news on this issue ?

Thanks

rodneykeeling commented 9 years ago

@vindarel We've just released a bug fix that should resolve this issue. Please take a look and let us know if you have further issues.

Thanks!

vindarel commented 9 years ago

Great news ! I'll tell you as soon as I test it.