如何使用python gsmmodem库发送多部分unicode短信? [英] how to send multipart unicode sms using python gsmmodem library?
问题描述
我可以使用python gsmmodem发送任何单部分或多部分的无Unicode短信.这是我的代码:
I can send any single part or multi part none Unicode sms message using python gsmmodem. this is my code :
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import logging
PORT = '/dev/ttyUSB2'
BAUDRATE = 115200
PIN = None
from gsmmodem.modem import GsmModem
def main():
print('Initializing modem...')
modem = GsmModem('/dev/ttyUSB2', 115200 )
modem.smsTextMode = False
modem.connect(PIN)
try:
message = u'ننننننننننننن نننننننتتتتتتتتتتت تتتتتتتتتتتتتتتت تتتتتتتتتتتتت تتتتتتتتت تتتتتتتتتتتتتتتتتتت تتتتتتت تتتتتتتتتتتتتتت تتتتتتتتتتتتتت تتتتتتتتتت'
modem.sendSms('09355666238' , message)
finally:
modem.close();
if __name__ == '__main__':
main()
它成功发送了一部分Unicode消息(少于70个字符),但对于超过70个字符的消息则抛出此错误消息:
it sends one part Unicode messages (less than 70 characters) successfully but for messages with more than 70 characters is throw this error message :
File "/usr/local/lib/python2.7/dist-packages/gsmmodem/modem.py", line 631, in sendSms
pdus = encodeSmsSubmitPdu(destination, text, reference=self._smsRef)
File "/usr/local/lib/python2.7/dist-packages/gsmmodem/pdu.py", line 341, in encodeSmsSubmitPdu
pdu.append(userDataLength)
ValueError: byte must be in range(0, 256)
我如何使用python发送多部分Unicode短信?
how i can send multipart unicode sms message using python?
推荐答案
I know this question is old but for anyone looking for a solution, use the forked version of python-gsmmodem by babca (works on python2 and python3)
请删除已安装的python-gsmmodem并安装此模块:
please remove already installed python-gsmmodem and install this module instead:
pip install python-gsmmodem-new
你很好走
这篇关于如何使用python gsmmodem库发送多部分unicode短信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!