我一遍又一遍地尝试使它起作用,但是它总是以
返回 {'code': 21603, 'message': "A 'From' phone number is required.", 'more_info': 'https://www.twilio.com/docs/errors/21603', 'status': 400}
有人可以帮忙吗?
我的代码:
import asyncio, aiohttp
async def main():
auth = aiohttp.BasicAuth(login="[sid]", password="[token]")
async with aiohttp.ClientSession(auth=auth) as session:
async with session.post("https://api.twilio.com/2010-04-01/Accounts/[sid]/Messages.json", params={"Body": "Test", "From": "[valid phone number]", "To": "[valid phone number]"}) as resp:
print(await resp.json())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
答案 0 :(得分:0)
使用data=payload
,将代码更改为以下形式:
import asyncio, aiohttp
async def main():
payload = {"Body": "Test", "From": "[valid phone number]", "To": "[valid phone number]"}
auth = aiohttp.BasicAuth(login="[sid]", password="[token]")
async with aiohttp.ClientSession(auth=auth) as session:
async with session.post("https://api.twilio.com/2010-04-01/Accounts/[sid]/Messages.json", data=payload) as resp:
print(await resp.json())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())