Number Portability Lookup - Sample Code for Carrier Query: PYTHON
PYTHON Sample Code:
The following code sample demonstrates how to query the carrier of a mobile subscriber by phone number via the NumberPortabilityLookup query service using the Python programming language.
Other Code Samples & Asterisk Carrier Lookup Examples
To find code samples for other languages, or number portability lookup integration examples for the Asterisk PBX, click here.
# Python Example code for NumberPortabilityLookup.com
# Put your username and password here:
# This is the number to be queried:
# Call API to perform HLR Query
conn = httplib.HTTPConnection("api.numberportabilitylookup.com")
data = conn.getresponse().read()
# Parse the response
# First line indicates success of the query
# Response returned OK - now read the data into variables
# This is a basic example querying a single number.
# If you queried more than one number in a single API call by delimiting MSISDNs
# with commas, you could extend the block below to loop through lines of response
# for each pair of msisdn/hlrdata until you reach response[n]=="ENDBATCH"
# Use the data as needed. For this example we will just print it to console:
print "MSISDN ",msisdn
print "MSC ",msc
print "IMSI ",imsi
# If we didn't get "QUERYOK", something broke - tell somebody!
print "Lookup error:",response