【发布时间】:2022-01-14 01:56:04
【问题描述】:
我希望使用 Python 中的 Twilio CLI 运行以下命令:
ngrok_cmd = "twilio phone-numbers:update "+ my_number " --sms url=https://localhost:5000"
os.system(ngrok_cmd)
该命令在终端上有效,但如果我尝试通过 python 执行该命令则无效。它不断给出以下错误:
sh: 1: twilio: not found
编辑:
我试过了:
ngrok_cmd = "/home/pi/.config/nvm/versions/node/v16.13.1/bin/twilio phone-numbers:update "+ my_number " --sms url=http://localhost:5000"
os.system(ngrok_cmd)
现在我收到此错误:
» Could not find profile.
» To create the profile, run:
twilio profiles:create
Alternatively, twilio-cli can use credentials stored in environment variables:
# OPTION 1 (recommended)
export TWILIO_ACCOUNT_SID=your Account SID from twil.io/console
export TWILIO_API_KEY=an API Key created at twil.io/get-api-key
export TWILIO_API_SECRET=the secret for the API Key
# OPTION 2
export TWILIO_ACCOUNT_SID=your Account SID from twil.io/console
export TWILIO_AUTH_TOKEN=your Auth Token from twil.io/console
Once these environment variables are set, a twilio-cli profile is not required and you may skip the "login" step.
但是,我已经在 /etc/profile 中设置了环境变量并通过以下方式进行了验证:
printenv | grep TWI
我不知道这个错误的原因是什么。谁能帮我解决这个问题?
【问题讨论】:
-
你从终端运行这个?你通过虚拟环境运行这个?如果是这样,你安装了这个包?
-
@Bernana 不是虚拟环境,在树莓派操作系统上运行。我遵循了这个:twilio.com/docs/twilio-cli/quickstart 并将我的密钥和令牌添加到树莓派作为环境变量。它可以在终端上运行,但不能通过 python...
-
我刚刚在我的笔记本电脑上试过这个。我安装了
twilioCLI 并运行os.system("twilio")并收到了帮助文本响应。您的 python 程序是否在您安装 Twilio CLI 的同一环境中运行? -
@philnash 感谢您的帮助!我在下面尝试了 Mark Setchell 的解决方案,但遇到了一个新错误……知道为什么会发生这种情况吗?
-
我看到你已经整理好了,感谢马克的帮助!
标签: python terminal raspberry-pi twilio twilio-cli