Issue #075 [WontFix/closed] - spi.xfer() uses bytes() call w/o encoding parameter which raises an error in Python 3

Posted by markus.dechert

What steps will reproduce the problem? When I import webiopi.devices.spi from WebIOPi 0.6 in a custom macro and try to call SPI.xfer using Python 3.2 I get the following stack trace: Traceback (most recent call last): File "/home/pi/Concierge/python/spicomm.py", line 73, in <module> print(getStatus()) File "/home/pi/Concierge/python/spicomm.py", line 66, in getStatus return sendCommand("GET_STATUS") File "/home/pi/Concierge/python/spicomm.py", line 28, in sendCommand c = spi.xfer('\0') File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.6.0-py3.2-linux-armv6l.egg/webiopi/devices/spi.py", line 128, in xfer _txbuff = bytes(txbuff) TypeError: string argument without an encoding

WebIOPi version used? => 0.6

Python version used? => 3.2.3

Distro used? (WebIOPi has only been tested on Raspbian Wheezy) => Raspbian Wheezy

Raspberry Pi board revision? (1 or 2) => 2

For Javascript side bugs, Browser? => n.n.

Please provide any additional information below. => https://docs.python.org/3.0/whatsnew/3.0.html - bullet 4 Although, spi.py has a case statement if (PYTHON_MAJOR >= 3): it calls the bytes() function without the encoding parameter.


Comment 1

Posted by trouch

when using xfer, you are supposed to use binary and provide a binary array, not a string. try to use spi.xfer([0x00]) instead


Comment 2

Posted by markus.dechert

Hi Eric,

you're right. It was PEBCAK. I'm quite new to Python in general and WebIOPi in particular. I can confirm that it's working the suggested way. Denoting all strings as byte strings (b'GET_STATUS' as well as b'\n') does the job. If you feel like you may consider adding a respective check in spi.py for this particular case (just in case I'm not the only newbie stumbling upon this) ;-)

Thanks for the quick support and keep up the good work! :-)


Comment 3

Posted by trouch

Fine, so I close the issue