Skip to content

Embedly client fails on certain URLs with KeyError #24

Description

@lsemel

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'

Activity

  1. joncotton commented on Dec 31, 2014

    @joncotton
    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'
    
  2. lsemel commented on Dec 31, 2014

    @lsemel
    Author

    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.

  3. mdrajibulislam commented on Jan 9, 2018

    @mdrajibulislam

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions