我试图使用请求向Twilio api发出POST请求,但每次都返回401状态代码,问题是什么?
url = 'https://api.twilio.com/2010-04-01/Accounts/ACe3a9b......27812bc6/Messages'
values = {
'To' : '+XXXXX' ,
'From' : '+XXXXXX' ,
'Body' : 'XXXX' ,
}
headers = {'AuthToken' :'XXXXXXXXXXXXXXXXX' ,
'AccountSid' : 'XXXXXXXXXXXX' }
response = requests.post(url , data = values , headers = headers )
谢谢
答案 0 :(得分:0)
看起来像Twilio的REST API需要HTTP Basic Auth。放弃标题,然后将其替换为...
from requests.auth import HTTPBasicAuth
auth = HTTPBasicAuth('AccountSid', 'AuthToken')
response = requests.post(url, data = values, auth = auth)