【python 监控报警】python 免费短信报警和电话报警

还觉得钉钉报警不够用,就启动电话报警了,twilio是神器。

1、打开twilio网址,注册一个账户。

官方网址:https://www.twilio.com/
2、安装库:

pip install twilio

3、注册并获取account_sid,auth_token,获取地址:twilio.com/console

4、填写你的手机号后,可以通过短信验证,也可以选择call you insteaded进行电话验证。
验证手机号码,加入需要打电话的电话号码。

短信报警:

from twilio.rest import Client

# Your Account SID from twilio.com/console
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# Your Auth Token from twilio.com/console
auth_token  = "your_auth_token"

client = Client(account_sid, auth_token)

message = client.messages.create(
    to="+15558675309", 
    from_="+15017250604",
    body="Hello from Python!")

print(message.sid)

电话报警:

from twilio.rest import Client

account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

call = client.calls.create(
    to="+14155551212",
    from_="+15017250604",
    url="http://demo.twilio.com/docs/voice.xml"
)

print(call.sid)

from 是twillo 给你的电话号码,to 是验证过的需要发送的号码。

官方参考文档:https://www.twilio.com/docs/libraries/python

你可能感兴趣的:(数据科学--python)