Created
August 26, 2010 19:25
-
-
Save mdornseif/552052 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import httplib | |
import urllib | |
import base64 | |
def send_fax_sipgate(uploadfiles, dest_number, guid='', username=None, password=None): | |
sip = Sipgate(username, password) | |
return sip.sendFax(uploadfiles, dest_number) | |
class Sipgate(object): | |
def __init__(self, username, password): | |
self.username = username | |
self.password = password | |
def sendFax(self, uploadfiles, dest_number, guid=''): | |
if len(uploadfiles) > 1: | |
raise ValueError('Sipgate currently only supports single PDF uploading') | |
if hasattr(uploadfiles[0], 'name'): | |
filedata = uploadfiles[0].read() | |
else: | |
filedata = uploadfiles[0] | |
params = urllib.urlencode({'version': '2.15', | |
'targets': dest_number, | |
'source': filedata,}) | |
auth = base64.encodestring('%s:%s' % (self.username, self.password))[:-1] | |
headers = {"Content-type": "application/x-www-form-urlencoded", | |
"Authorization": "Basic %s" % auth} | |
conn = httplib.HTTPSConnection("api.sipgate.net") | |
conn.request("POST", "/my/events/faxes/", params, headers) | |
response = conn.getresponse() | |
print response.status, response.reason | |
data = response.read() | |
print data | |
conn.close() | |
return guid | |
send_fax_sipgate([open('/Users/md/code2/git/huShop/9-AT-mahnung-WL115.pdf')], dest_number='+49219xxx2', | |
username='xxx@xxx', | |
password='xxx') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This currently returns: