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

Embedly client fails on certain URLs with KeyError #24

Open
lsemel opened this issue Dec 29, 2014 · 3 comments
Open

Embedly client fails on certain URLs with KeyError #24

lsemel opened this issue Dec 29, 2014 · 3 comments

Comments

@lsemel
Copy link

lsemel commented Dec 29, 2014

This happens with the latest version of the client 0.5.0

from embedly import Embedly
from django.conf import settings
client = Embedly(settings.EMBEDLY_EXTRACT_KEY)
url = u'http://aldianews.com/articles/politics/cost-story-—-interactive-storymap-about-conflict-journalism/36116'
thumbnail_max_width=320
words=100
embedly_obj = client.extract(url, maxwidth=thumbnail_max_width, words=words)

The resulting error is:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/lsemel/www/virtualenvs/muckrack/src/embedly/embedly/client.py", line 169, in extract
    return self._get(1, 'extract', url_or_urls, **kwargs)
  File "/Users/lsemel/www/virtualenvs/muckrack/src/embedly/embedly/client.py", line 121, in _get
    query += '&url=%s' % quote(url_or_urls)
  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1282, in quote
    return ''.join(map(quoter, s))
KeyError: u'\u2014'
@joncotton
Copy link
Contributor

Python 2's quote() is tripping up on the em dash in that url. It will work if you don't use a unicode string. (Python 3 doesn't have such unicode issues.)

# Python 2
from urllib import quote
quote("—")
> '%E2%80%94'
quote(u"—")
> KeyError: u'\u2014'

@lsemel
Copy link
Author

lsemel commented Dec 31, 2014

Since that's not obvious it might be useful if the library checked if the string is a unicode and converted it to whatever encoding it needs.

@mdrajibulislam
Copy link

add encode('utf8')
urllib.quote('-'.encode('utf8'))

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

3 participants