如何使用python gsmmodem模块发送unicode字符?

2024-10-01 04:45:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用python-gsmmodem-newv0.12模块发送unicode字符。 https://www.pydoc.io/pypi/python-gsmmodem-new-0.12/autoapi/modem/index.html 当我发送GSM-7信息时,它就工作了。你知道吗

但是,当我试图发送unicode消息时,它会显示"Unable to set SMS encoding (enocoding UCS2 not supported)"。你知道吗

try:
    modem.sendSms('3473438473', '测试')
except TimeoutException:
    sys.stderr.write('Time out.\n')
except CommandError:
    sys.stderr.write('Failed.\n')

结果如下:

Traceback (most recent call last):

File "/Users/user/Sites/mobilesmsPython/mobileSMS.py", line 651, in <module>
main()

File "/Users/user/Sites/mobilesmsPython/mobileSMS.py", line 389, in main
modem.sendSms('3473438473', '测试')

File "/Users/user/Sites/mobilesmsPython/gsmmodem/modem.py", line 919, in sendSms
self.smsEncoding = 'UCS2'

File "/Users/user/Sites/mobilesmsPython/gsmmodem/modem.py", line 712, in smsEncoding
raise ValueError('Unable to set SMS encoding (enocoding {0} not supported)'.format(encoding))

ValueError: Unable to set SMS encoding (enocoding UCS2 not supported)

Tags: toinpylinesmsuserssitesencoding