【问题标题】:Credentials are required to create a TwilioClient创建 TwilioClient 需要凭据
【发布时间】:2020-09-16 00:06:08
【问题描述】:

我想通过 Twilio 模块使用 python 发送 whatsapp 消息。我从 youtube 获得了一个代码,当运行代码时,它出现了一个错误

Traceback (most recent call last):
  File "whatsapp.py", line 4, in <module>
    client = Client()
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\twilio\rest\__init__.py", line
54, in __init__
    raise TwilioException("Credentials are required to create a TwilioClient")
twilio.base.exceptions.TwilioException: Credentials are required to create a TwilioClient

这是我的代码:

from twilio.rest import Client

client = Client()

from_whatsapp_number = 'whatsapp: +60***86744'
to_whatsapp_number = 'whatsapp: +8134***727'

client.messages.create(body='Testing message using python',
                       from_ = from_whatsapp_number,
                       to = to_whatsapp_number)

【问题讨论】:

标签: python twilio message whatsapp


【解决方案1】:

docsClient 应声明如下:

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)

当您声明您的 Client 时,您错过了您的 account_sidauth_token
正如@Alan 指出的那样,如果account_sidauth_token 没有在Client 中声明,Twilio 会分别将它们作为环境变量查找TWILIO_ACCOUNT_SIDTWILIO_AUTH_TOKEN

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多