Skip to content

Instantly share code, notes, and snippets.

@mdornseif
Created August 26, 2010 19:25
Show Gist options
  • Save mdornseif/552052 to your computer and use it in GitHub Desktop.
Save mdornseif/552052 to your computer and use it in GitHub Desktop.
#!/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')
@mdornseif
Copy link
Author

This currently returns:

400 Bad Request
<html><head><title>Status page</title></head>
<body style="font-family: sans-serif;">
<h3>Bad Request</h3>
<B>content must be application/pdf</B>
<p>You can get technical details <a href="http://www.live.sipgate.de/api/rest/">here</a>.</p>
</body></html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment