Python
This section shows sample usage in various environments.
Python 2.7, httplibPython 2.7, urllib2Python 2.7, Requests/httplib3
import sys
import httplib
import urllib
import base64
URL = "smartreplypath.spirius.com"
PORT = 55001
CREDENTIALS = base64.b64encode("Username:Password")
def send_replypath_sms_v1(dest, message):
try:
encoded_dest = urllib.quote_plus(dest)
encoded_mess = urllib.quote_plus(message)
h = httplib.HTTPSConnection(URL, PORT, timeout=10)
query = "/v1/replypath/sendsms/%s/%s" % (encoded_dest, encoded_mess)
h.putrequest("GET", query)
h.putheader("Accept", "application/json")
h.putheader("Authorization", "Basic " + CREDENTIALS)
h.endheaders()
r = h.getresponse()
if (r.status != 200):
return ("%d %s") % (r.status, r.reason)
return r.read()
except Exception, e:
sys.stderr.write(str(e))
finally:
if (h is not None):
h.close()
print send_replypath_sms_v1("+46123456789", "Hello world")
import sys
import httplib
import urllib
import urllib2
import base64
URL = "https://smartreplypath.spirius.com:55001/v1/replypath/sendsms?"
CREDENTIALS = base64.b64encode("Username:Password")
def send_replypath_sms_v2(dest, message):
try:
params = {
'To': dest, 'Msg': message
}
encoded_params = urllib.urlencode(params)
request = urllib2.Request(URL + encoded_params)
request.add_header("Authorization", "Basic %s" % CREDENTIALS)
response = urllib2.urlopen(request)
return response.read()
except urllib2.HTTPError, error:
return error.read()
except Exception, e:
sys.stderr.write(str(e))
return ""
print send_replypath_sms_v2("+46123456789", "Hello world")
This example uses the third party library Requests, which makes sending HTTP requests easier.
import sys
import requests
URL = "https://smartreplypath.spirius.com:55001/v1/replypath/sendsms"
USER = "Username"
PASS = "Password"
def send_replypath_sms_v3(dest, message):
try:
_params = {
'To': dest, 'Msg': message
}
r = requests.get(URL, params=_params, auth=(USER,PASS), timeout=10)
return r.text
except Exception, e:
sys.stderr.write(str(e))
return ""
print send_replypath_sms_v3("+46123456789", "Hello world")