Account  |   Register  |   Pricing  |   Asterisk  |   HTTP API   |   ENUM   |   Code  |   Batch Client   |   Networks  |   Status  |   About  |   Contact

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.

Code Sample:

# Python Example code for

import httplib

# Put your username and password here:

# This is the number to be queried:

# Call API to perform HLR Query
conn = httplib.HTTPConnection("")
conn.request("GET", "/npl?user="+username+"&pass="+password+"&msisdn="+number+"&apiver=2.4")
data = conn.getresponse().read()

# Parse the response

# First line indicates success of the query
if response[0]=="QUERYOK":

	# 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"

	(msisdn,hlrdata)=response[1].split(" ",2)

	# 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[0]

© 2016 Comcetera Ltd. is a product of Comcetera™ Ltd
Comcetera Ltd is Registered in England, Company 6058188 at Unit 13 Freeland Business Park, Poole BH16 6FH.