This function self.ble.get_public_key_generated() gives TypeError: function takes 0 positional arguments but 1 were given #15945
Unanswered
brianreinhold
asked this question in
RP2040 / Pico
Replies: 2 comments 2 replies
-
Hi, I think the issue here is that the function is being run as a method of a class instance - in this case there is av single argument of Try running it as Otherwise the C functions can be declared as accepting 1 arg and just ignore the arg. |
Beta Was this translation helpful? Give feedback.
2 replies
-
Try to call the method without the self reference, for example: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This is an exercise in accessing a C method from a micropython application
I have this micropython application code
which gives this error:
TypeError: function takes 0 positional arguments but 1 were given
. Clearly no arguments are given.What the method should do is return true if a set of cryptography keys have been generated by the btstack. The results of the
print(dir(self.ble))
certainly show that the method exists (it's next to last in the list):The method is defined in
lib/btstack/src/btstack_crypto.c
and declared inlib/btstack/src/btstack_crypto.h
. Very simple.To access it in micropython at the application level one has the usual hierarchy
First the mapping of the function from python to C and back which appears in the
modbluetooth.c
file:where the macro
STATIC MP_DEFINE_CONST_FUN_OBJ_0
as I understand it is supposed to handle a method that takes 0 arguments.Second the inclusion of this method in the
STATIC const mp_rom_map_elem_t bluetooth_ble_locals_dict_table[]
as the following entry:{ MP_ROM_QSTR(MP_QSTR_get_public_key_generated), MP_ROM_PTR(&bluetooth_ble_get_public_key_generated_obj) },
and its declaration in
modbluetooth.h
uint8_t mp_bluetooth_get_public_key_generated(void);
And finally it's presence in the btstack-specific modbluetooth file
modebluetooth_btstack.c
Now it's certainly easy to get messed up on the
mp_bluetooth_*
,bluetooth_ble_*
and itsobj
signatures but as far as I see it is all done correctly. This method is clearly setup to take 0 arguments and it compiles and builds with no warnings or error messages. Yet when I call it from a micropython application I get an error saying I am passing in an argument which is clearly not the case.I have spent hours examining the code, redoing the firmware build always getting the same result. I am clueless. Must be something stupid I do not see because I have looked at it too long. Any insight from someone who is better versed in this python to C interfacing is GREATLY appreciated!
Beta Was this translation helpful? Give feedback.
All reactions