Python 2.7 python 2.7 UnicodeDecodeError pyserial
我试图从这里获得pySIMreader,并使用python 2.7。我一直收到以下错误:Python 2.7 python 2.7 UnicodeDecodeError pyserial,python-2.7,unicode,decode,pyserial,Python 2.7,Unicode,Decode,Pyserial,我试图从这里获得pySIMreader,并使用python 2.7。我一直收到以下错误: Traceback (most recent call last): File "pySimReader.py", line 267, in buttonConnectReader self.SIM.connectReader() File "/home/john/Plocha/pySimReader-Serial-src-v2/pySIMserial.py", line 113, in
Traceback (most recent call last):
File "pySimReader.py", line 267, in buttonConnectReader
self.SIM.connectReader()
File "/home/john/Plocha/pySimReader-Serial-src-v2/pySIMserial.py", line 113, in connectReader
res = self.openSession(self.getReaderName())
File "/home/john/Plocha/pySimReader-Serial-src-v2/pySIMserial.py", line 145, in openSession
baudrate=9600)
File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 260, in __init__
self.open()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 276, in open
raise SerialException("could not open port %s: %s" % (self._port, msg))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 13: ordinal not in range(128)
我知道有很多UnicodeDecodeError的帖子,我也试着去弄清楚,但我肯定错过了什么
以下是相关代码:
try:
if (os.name == "posix"):
s = "/dev/ttyUSB0\t"
#s = "/dev/cu.PL2303-3B1\t"
if (os.name == "nt"):
for i in range(1,10):
s += "COM"+str(i)+"\t"
except:
print_exc()
for i in s.split("\t"):
if i:
self.listbox.Append(i)
...
def getReaderName(self):
return self.readerName
def connectReader(self):
if not self.getReaderName():
self.selectNewReader()
if self.getReaderName():
res = self.openSession(self.getReaderName())
if res == 0:
self.state = SIM_STATE_CONNECTED
self.gatherInfo()
...
def openSession(self, portname):
self.serialport = serial.Serial(port=portname,
parity=serial.PARITY_EVEN,
bytesize=serial.EIGHTBITS,
stopbits=serial.STOPBITS_TWO,
timeout=1,
xonxoff=0,
rtscts=0,
baudrate=9600)
...
def selectNewReaderOK(self, *args):
self.readerName = self.listbox.GetStringSelection()
self.closeDialog()
你能告诉我,type(self.listbox.GetStringSelection)type(self.listbox.GetStringSelection)打印的结果是什么吗