Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
26 lines (23 sloc) 757 Bytes
import urllib
import urllib2
from import CommandError
from django.utils import simplejson as json
from django.conf import settings
def call(method, data, post=False):
Calls `method` from the DISQUS API with data either in POST or GET.
Returns deserialized JSON response.
url = "%s%s" % ('', method)
if post:
# POST request
url += "/"
data = urllib.urlencode(data)
# GET request
url += "?%s" % urllib.urlencode(data)
data = ''
res = json.load(urllib2.urlopen(url, data))
if not res['succeeded']:
raise CommandError("'%s' failed: %s\nData: %s" % (method, res['code'], data))
return res['message']
Something went wrong with that request. Please try again.