python发送短信内容_通过Python发送短信

我正在使用以下代码连接到手机以发送短消息:import serial

import time

phone = serial.Serial()

phone.baudrate = 38400

phone.bytesize = 8

phone.stopbits = 1

phone.xonxoff = 0

phone.rtscts = 0

phone.timeout = 0

phone.port = 3 #try different ports here, if this doesn't work.

phone.parity=serial.PARITY_NONE

phone.open()

print phone.portstr

recipient = "+929409778"

message = "We did it!"

print ("I did come after it")

try:

time.sleep(0.5)

phone.write(b'ATZ\r')

time.sleep(0.5)

phone.write(b'AT+CMGF=1\r')

time.sleep(0.5)

phone.write(b'AT+CMGS="' + recipient.encode() + b'"\r')

time.sleep(0.5)

phone.write(message.encode() + b"\r")

print (message)

time.sleep(0.5)

phone.write(bytes([26]))

time.sleep(0.5)

phone.readall()

finally:

phone.close()

我可以连接电话,但无法发送消息。它没有给我一个错误,所以我不知道从哪里开始调试。在

我的代码有什么问题我没有看到吗?在


版权声明:本文为weixin_33502772原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。