问题描述
import requests
url = "https://api.aql.com/v2/sms/send"
token='07ae4cca3f90a49347ccb5cfghypdngthwss85d9ce71862663e4b8162b366ba6c2db8f5f'
msg = "Ambient temperature has dropped to 10 Deg.C"
phone = "441234567890"
payload = "{\"destinations\" : [\"447753448024\"],\"message\": \"Hello,I am a message\"}"
headers = {
'x-auth-token': token,'content-type': "application/json"
}
response = requests.post(url,data=payload,headers=headers)
print(response.text)
我希望在位置插入变量phone和msg或文字
任何帮助都会感激
解决方法
您可以使用json
中的.post()
属性,它将处理content-type
标头以及从dict
到str
的转换
url = "https://api.aql.com/v2/sms/send"
token='07ae4cca3f90a49347ccb5cfghypdngthwss85d9ce71862663e4b8162b366ba6c2db8f5f'
msg = "Ambient temperature has dropped to 10 Deg.C"
phone = "441234567890"
payload = {'destinations':[phone],'message':msg}
response = requests.post(url,json=payload,headers={'x-auth-token': token})