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

OEmbedResource.create() fails on '%' in width value returned by SoundCloud oembed response #34

Open
ghing opened this issue Mar 21, 2012 · 0 comments

Comments

@ghing
Copy link

ghing commented Mar 21, 2012

Calling the SoundCloud endpoint with minimal parameters returns a width="100%" in the response. For example http://soundcloud.com/oembed?url=http://soundcloud.com/ghing/the-calling-for-diychi-comp&format=json produces this response:

{
    "version": 1,
    "type": "rich",
    "provider_name": "SoundCloud",
    "provider_url": "http://soundcloud.com",
    "height": 166,
    "width": "100%",
    "title": "The Calling (for DIYCHI comp) by ghing",
    "description": "Finished version of \"The Calling\" for the DIY CHI comp",
    "html": "<iframe width=\"100%\" height=\"166\" scrolling=\"no\" frameborder=\"no\" src=\"http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F27467434&show_artwork=true\"></iframe>"
}

I'm not sure whether or not this adheres to the oEmbed spec, but it's a popular service, so it should be handled.

The problem is in these lines in OEmbedResource.create():

data['width'] = data.get('width') and int(data['width']) or None
data['height'] = data.get('height') and int(data['height']) or None

the call to int(data['width']) raises a ValueError because of the '%' in data['width']

A simple workaround would be to wrap those lines in a try/except like this:

try:
    data['width'] = data.get('width') and int(data['width']) or None
except ValueError:
   data['width'] = None
try:
    data['height'] = data.get('height') and int(data['height']) or None
except ValueError:
    data['height'] = None
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

Successfully merging a pull request may close this issue.

1 participant