Removed requests dependency

pull/46/head
Karl Hobley 2014-02-14 13:09:08 +00:00
rodzic 9023432f5a
commit c4875dfd4d
2 zmienionych plików z 8 dodań i 5 usunięć

Wyświetl plik

@ -48,7 +48,6 @@ setup(
"beautifulsoup4>=4.3.2", "beautifulsoup4>=4.3.2",
"lxml>=3.3.0", "lxml>=3.3.0",
"BeautifulSoup==3.2.1", # django-compressor gets confused if we have lxml but not BS3 installed "BeautifulSoup==3.2.1", # django-compressor gets confused if we have lxml but not BS3 installed
"requests==2.2.1",
], ],
zip_safe=False, zip_safe=False,
) )

Wyświetl plik

@ -1,11 +1,12 @@
import sys import sys
from importlib import import_module from importlib import import_module
import requests
from django.conf import settings from django.conf import settings
from datetime import datetime from datetime import datetime
from django.utils import six from django.utils import six
from wagtail.wagtailembeds.oembed_providers import get_oembed_provider from wagtail.wagtailembeds.oembed_providers import get_oembed_provider
from wagtail.wagtailembeds.models import Embed from wagtail.wagtailembeds.models import Embed
import urllib2, urllib
import json
class EmbedNotFoundException(Exception): pass class EmbedNotFoundException(Exception): pass
@ -91,10 +92,13 @@ def oembed(url, max_width=None):
params['maxwidth'] = max_width params['maxwidth'] = max_width
# Perform request # Perform request
r = requests.get(provider, params=params) request = urllib2.Request(provider + '?' + urllib.urlencode(params))
if r.status_code != 200: request.add_header('User-agent', 'Mozilla/5.0')
try:
r = urllib2.urlopen(request)
except urllib2.URLError:
raise EmbedNotFoundException raise EmbedNotFoundException
oembed = r.json() oembed = json.loads(r.read())
# Convert photos into HTML # Convert photos into HTML
if oembed['type'] == 'photo': if oembed['type'] == 'photo':