Closed jimbobbennett closed 4 years ago
PR #21 raised to remove this parameter, if this is the correct fix
Odd, I am able to run this at REPL and don't get the same error.
>>> bytes("hello", "utf-8")
b'hello'
@FoamyGuy - I think it is because it is a bytearray
.
Just tested in the REPL:
>>> b = bytearray(10)
>>> bytes(b, 'utf-8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: wrong number of arguments
Looks like possible the issue is more related to the bytearray than the encoding param I use a bytebuffer instead of a string it reports the error:
>>> buffer = bytearray()
>>> bytes(buffer, "utf-8")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: wrong number of arguments
This does not appear to be possible in CPython 3.7 either, though the error is different than CircuitPython:
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> buffer = bytearray()
>>> bytes(buffer, "utf-8")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: encoding without a string argument
I've changed my PR to check the type, and not pass the encoding for bytearray
, but keep it for other types.
Just tested this with the latest bundle and it's all working. Thanks @FoamyGuy and @tannewt for your help with this.
I have a
bytearray
containing image data from the TTL camera sample. I want to POST this as an octet stream to a REST endpoint.My code:
When I run this I get the following:
Running the code locally I've tracked down the error to this line:
If I change the call to
bytes()
to remove the encoding parameter, it works.Does the CircuitPython implementation of
bytes
have an encoding parameter?