Skip to content

Instantly share code, notes, and snippets.

@FZambia
Created February 2, 2015 21:51
Show Gist options
  • Save FZambia/4dc8dbe7fe7460cb8797 to your computer and use it in GitHub Desktop.
Save FZambia/4dc8dbe7fe7460cb8797 to your computer and use it in GitHub Desktop.
Send data to Centrifuge as JSON (coming soon)
# coding: utf-8
try:
from urllib.request import urlopen, Request
except ImportError:
from urllib2 import urlopen, Request
try:
from urllib import urlencode
except ImportError:
# python 3
# noinspection PyUnresolvedReferences
from urllib.parse import urlencode
try:
import urllib.parse as urlparse
except ImportError:
import urlparse
import six
import hmac
import json
data = json.dumps({
"data": encoded_data,
"sign": sign
})
req = Request(url, data, {'Content-Type': 'application/json'})
try:
response = urlopen(
req,
timeout=self.timeout
)
except Exception as e:
return None, e
else:
data = response.read()
result = json.loads(data.decode('utf-8'))
return result, None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment