Look up a number with Python

You can quickly see how the Number Lookup API works by looking up a number using the API.

In this guide you will learn:
  1. How to set up your Python application.
  2. Look up your phone number.

What you need to know before you start

Before you can get started, you need the following already set up:

Set up your Python application and install dependencies

We'll be using the requests module to make HTTP requests. If it's not already installed globally, open a command prompt and use the following command to install the requests module:
Copy
Copied
pip install requests
Create a new file named app.py and paste the provided "app.py" code found on this page into the file.
Note:

This tutorial uses basic authentication for testing purposes. We recommend using a signed request for authentication in a production environment. You can follow the steps in this guide, but use the code samples from here to use request signing authentication instead.

Fill in your parameters

Before you can run the code, you need to update some values so you can connect to your Sinch account. Update the following parameters with your own values:

Assign your values to the following parameters:

ParameterYour value
keyThe key found on your Sinch dashboard.
secretThe secret found on your Sinch dashboard.
numberThe phone number that you want to look up in E.164 format.

Save the file.

Look up your phone number

Now you can execute the code and look up your phone number. Run the following command:

Copy
Copied
python app.py

You should receive a response in your console with details about the phone number you specified.

Troubleshooting tip

If after running your app you receive a 5000 error response, you may have forgotten to save your file after adding your authentication values. This is an easy mistake to make! Try saving the file and running the app again.

Additional resources

We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.