【问题标题】:Send Sms through Python通过 Python 发送短信
【发布时间】:2012-04-07 09:39:44
【问题描述】:

我正在使用以下代码连接手机以发送短信:

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()

我可以连接手机,但无法发送消息。它没有给我一个错误,所以我不确定从哪里开始调试。

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

【问题讨论】:

  • 将来,当您使用完整、连贯的句子以及适当的大写和标点符号时,它会有所帮助。避免像“plz”“ur”等“文字说话”。
  • “它没有给我错误”你怎么知道?
  • 好的,将来会尝试这样做.... @IgnacioVazquez-Abrams 因为它没有给我语法错误。手机最后关机了,我就是这么知道的!

标签: python www-authenticate


【解决方案1】:

尝试使用 phone.flush() 刷新电话流,看看它是否通过。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-05
    • 1970-01-01
    相关资源
    最近更新 更多