python发送短信内容_通过Python发送短信
我正在使用以下代碼連接到手機(jī)以發(fā)送短消息: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()
我可以連接電話(huà),但無(wú)法發(fā)送消息。它沒(méi)有給我一個(gè)錯(cuò)誤,所以我不知道從哪里開(kāi)始調(diào)試。在
我的代碼有什么問(wèn)題我沒(méi)有看到嗎?在
總結(jié)
以上是生活随笔為你收集整理的python发送短信内容_通过Python发送短信的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: ubuntu锁定mysql到任务栏_ub
- 下一篇: vb mysql 字符串转日期_VB常用