← index #8414Issue #136
Related · high · value 4.160
QUERY · ISSUE

function doesn't take keyword arguments in micropython

openby SamRoy259opened 2022-03-14updated 2023-04-30
py-core

i=10
i.to_bytes(1,byteorder='little') * 4

CANDIDATE · ISSUE

Here is an error in umqtt.simple.py line 139

closedby EXboysopened 2016-12-19updated 2016-12-19

line 139 self.sock.write(qos.to_bytes(1)) raise error

error details:

TypeError: function missing 1 required positional arguments

and i find some information about this function:

int.to_bytes(length, byteorder, *, signed=False)

>>> (1024).to_bytes(2, byteorder='big')
b'\x04\x00'
>>> (1024).to_bytes(10, byteorder='big')
b'\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00'
>>> (-1024).to_bytes(10, byteorder='big', signed=True)
b'\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00'
>>> x = 1000
>>> x.to_bytes((x.bit_length() // 8) + 1, byteorder='little')
b'\xe8\x03'

but when run (1024).to_bytes(2, byteorder='big') in micropython on esp8266, it still can not work.

TypeError: function does not take keyword arguments

what wrong with it? Thanks!

4 comments
EXboys · 2016-12-19

When i comment this line , it can work throght. But I can't receive message published by another client whitch running on my computer(ubuntu 16.04)

dpgeorge · 2016-12-19

There was a recent fix to MicroPython to require the "byteorder" parameter in the to_bytes and from_bytes functions (to make it have the same behaviour as CPython). This change was not propagated (yet!) to all the libraries in this repo.

To fix it for now, use the method without the keyword argument, like this: qos.to_bytes(1, 'little')

EXboys · 2016-12-19

Thanks! I have tried it, and it works.

pfalcon · 2016-12-19

Fixed in master/latest release.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied