希望stackoverflow社区能帮助我。我想在 python 中使用 POST api 发送短信,这是我尝试过的:
>> post_data = {"To": "my-phone-number", "From": TWILIO_NUMBER, "Body": "Test message", "AccountSid": "my-account-sid", "AuthToken":"my-auth-token"}
>> import requests
>> response = requests.post('https://api.twilio.com/2010-04-01/Accounts/my-account-sid/Messages', data=post_data)
我收到以下错误:
response.content
"<?xml version='1.0' encoding='UTF-8'?>\n<TwilioResponse><RestException><Code>20003</Code><Detail>Your AccountSid or AuthToken was incorrect.</Detail><Message>Authentication Error - No credentials provided</Message><MoreInfo>https://www.twilio.com/docs/errors/20003</MoreInfo><Status>401</Status></RestException></TwilioResponse>"
我什至尝试了这个请求 URI:
>> response = requests.post('https://api.twilio.com/2010-04-01/Accounts/my-account-sid:my-auth-token/Messages', data=post_data)
仍然是同样的错误:-/
我的 uri 错误还是 POST 参数不完整?老实说,对于 POST api,文档并不是很好:-/
更新:任何仍在寻找答案的人,您都可以看到已接受的答案或更新请求,如下所示:
response = requests.post('https://api.twilio.com/2010-04-01/Accounts/my-account-sid/Messages', data=post_data, auth=('my-account-sid', 'my-auth-token'))