Skip to content

Python

This section shows sample usage in various environments.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sys
import httplib
import base64

URL = "get1-spirilookup.spiricom.spirius.com"
PORT = 54011
CREDENTIALS = base64.b64encode("Username:Password")

def lookup(service, msisdn):
  try:
  h = httplib.HTTPSConnection(URL, PORT, timeout=60)
  query = "/v1/lookup/%s/%s" % (service, msisdn)
  h.putrequest("GET", query)
  h.putheader("Accept", "text/plain")
  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 lookup("sweden", "46731290000")
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import requests
URL = "https://get-spirilookup.spiricom.spirius.com"
PORT = "54011"
USER = "Username"
PASS = "Password"


def lookup(service, msisdn):
    path = f"/v1/lookup/{service}/{msisdn}"
    r = requests.get(
        f"{URL}:{PORT}{path}",
        headers={"Accept": "text/plain"},
        auth=(USER, PASS),
        verify=False
    )
    return r.text


print(lookup("sweden", "46731290000"))
print(lookup("basic", "46731290000"))