"Python programe" uses Python to send voice verification

Source: Internet
Author: User
Tags virtualenv

Using Python to send a voice verification code to your phone requires the following tools:

    • Virtualenv Creating a standalone runtime environment

    • Twilio account to call the appropriate API

    • Twilio Python library, version 5.7.0

1. Create a standalone operating environment using virtualenv:

# installation PIP3 Install virtualenv # the corresponding directory, create the environment virtualenv--no-site-packages venv

With parameters --no-site-packages , all third-party packages installed in the system Python environment will not replicate, so that we have a "clean" python runtime environment without any third-party packages.

The new Python environment is placed in the directory under the current directory venv . With venv This Python environment, you can source enter the environment:

SOURCE venv/bin/Activate
(venv) [Email protected]:~/phonecall$

Notice that the command prompt is changed and has a (venv) prefix that indicates that the current environment is a venv python environment named.

2. Install the Twilio Runtime Library:

Pip Install twilio==5.7.0

Under the environment, the system Python environment is not affected by the installation of the packages installed in venv pip venv this environment. In other words, the venv environment is created specifically for myproject this application.

Exiting the current venv environment, using deactivate commands

Virtualenv is to copy the system Python to a virtualenv environment, when the command source venv/bin/activate into a virtualenv environment, VIRTUALENV will modify the relevant environment variables, let the command python and pip All point to the current virtualenv environment.

3. Write Python code phone_call.py:

#!/usr/bin/env python#-*-coding:utf-8-*- fromTwilio.restImporttwiliorestclient#Twilio Application for the number "+18568884457"Twilio_phone_number =""#The number you need to dial "+86188xxxxxxxx"Dial_numbers = ["",]#TwiML Decide how to handle this sessionTwiml_instructions_url ="Https://demo.twilio.com/docs/voice.xml"#account SID & TokenClient = Twiliorestclient ("acxxxxxxxxxx","yyyyyyyyyy")defdial_numbers (numbers_list):"""Send voice commands"""     forNumberinchnumbers_list:Print("dialing"+Number )#set request method for Get XML directiveClient.calls.create (To=number, from_=twilio_phone_number, url=twiml_instructions_url, method="GET")if __name__=="__main__": Dial_numbers (dial_numbers)

Dial_numbers fill in the number that needs to be dialed (plus area code), Twilio_phone_number and TWILIO account SID, Token is obtained in the TWILIO console

4, registered Twilio account number,?? Website

5. Get Twilio account SID, Token

6, TWILIO test account can only give their own authentication or the number to send information, or to upgrade account recharge 20 knives, a phone charge of 0.028 knives ~

7, click the number, configure the number, fill in the required XML address and get the way get, POST

8, fill in the XML to get the address,?? Document content Format Reference link

9. Run the code:

Python phone_call.py

      

"Python programe" uses Python to send voice verification

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.