首页 > 解决方案 > 通过 python 脚本发送短信

问题描述

在下面的程序中,我试图向选定的号码发送短信。使用 sql 查询从表中选择数字,然后将其存储在 pr 中。在有效载荷中,我不想直接输入数字,而是想用pr一一发送短信。但在这种情况下,它显示数字丢失。有什么办法吗?

import sqlite3

import requests

conn=sqlite3.connect("Face.db")

cmd="select mnumber from peoples where presence=1"

cursor=conn.execute(cmd)

for row in cursor:
pr=int(row[0])


url = "https://www.fast2sms.com/dev/bulk"

payload = "sender_id=FSTSMS & message=good morning & language=english & route=p & numbers=pr"
headers = {
 'authorization': "zg6YJqFs2wCbPGM9H5p4QOiDlSAca7KvIhWrLxNmEX0RoVBdkefWOGmNVHeR9d6lM8Kzn07gQPBhusFU",
 'Content-Type': "application/x-www-form-urlencoded",
 'Cache-Control': "no-cache",
 }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

conn.commit()
conn.close()

标签: python

解决方案


改变这个

"sender_id=FSTSMS & message=good morning & language=english & route=p & numbers=pr"

对此

"sender_id=FSTSMS & message=good morning & language=english & route=p & numbers="+pr

以上应该工作。我注意到您在字符串中添加了 pr


推荐阅读