Python twilio:从“无”中升起钥匙错误(钥匙)
我正在尝试使用twilio发送消息,我得到以下错误。如何解决此错误Python twilio:从“无”中升起钥匙错误(钥匙),python,twilio,Python,Twilio,我正在尝试使用twilio发送消息,我得到以下错误。如何解决此错误 import os from twilio.rest import Client account_sid = os.environ['testtest'] auth_token = os.environ['testtesttest'] client = Client(account_sid, auth_token) message = client.messages \ .create(
import os
from twilio.rest import Client
account_sid = os.environ['testtest']
auth_token = os.environ['testtesttest']
client = Client(account_sid, auth_token)
message = client.messages \
.create(
body="Join Earth's mightiest heroes. Like Kevin Bacon.",
from_='+16813203595',
to='+12345678'
)
print(message.sid)
设置环境变量取决于操作系统 以下是链接列表,具体取决于您使用的机器
您还需要设置您的twilio帐户,并从中获得您的
帐户sid
和身份验证令牌
,以便轻松测试您的代码:一个简单的修复方法是不使用环境变量,
将代码重新构造为:
from twilio.rest import Client
account_sid = 'testtest'
auth_token = 'testtesttest'
client = Client(account_sid, auth_token)
message = client.messages \
.create(
body="Join Earth's mightiest heroes. Like Kevin Bacon.",
from_='+16813203595',
to='+12345678'
)
print(message.sid)
一旦高兴,然后考虑TWILIO的响应,如果你想要这个问题的简单答案,你可以切换到Env变量
< P>,如果你想要这个问题的简单答案。 在Twilio的示例代码中,它有以下两行account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
实际上,您并没有将您的Twilio帐户sid和令牌放在这些行中。保持原样。不要更改这些行。不要添加您的帐户sid和令牌。而是在命令提示下键入:
export TWILIO_ACCOUNT_SID=your_SID_account
export TWILIO_AUTH_TOKEN=your_auth_token
现在运行脚本,脚本将拉动您的环境键。以这种方式确保您的信息安全:)环境变量testest可能未设置-您需要使用凭据进行设置。@PaulBrennan如何设置它?
export TWILIO_ACCOUNT_SID=your_SID_account
export TWILIO_AUTH_TOKEN=your_auth_token