Error 401 in publishing properties with Python library

I am having troubles setting a variable using Python, while reading its value works fine.

I use the Arduino IoT Client library and it works perfectly when I need to retrieve a value from a Thing. On the other hand, I always get a 401 Unauthorized error when I try to set a value. This is the code I am using:

#Set the switch to ON
switchValue = {'value': True}
try:
   resultUpdate = properties.properties_v2_publish(station_id, switch_id, switchValue)
   print(resultUpdate)
except ApiException as e:
     print("Got an exception: {}".format(e))

When I run the Python script I get this error message:

Got an exception: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Cache-Control': 'no-cache, no-store, must-revalidate', 'Content-Type': 'application/vnd.goa.error+json', 'Date': 'Mon, 27 Mar 2023 13:04:58 GMT', 'Expires': '0', 'Pragma': 'no-cache', 'Vary': 'Accept-Encoding, Origin', 'Content-Length': '185', 'Connection': 'keep-alive'})
HTTP response body: {"id":"rV5tNlCD","code":"unauthorized","status":401,"detail":"not allowed to publish the property thingID=NNNNNNNNNNNNNNNNNNNNNNN","meta":{"requestId":"nGa9vxA59P-83262"}}

As said, Thing ID and variable ID work fine when retrieving values, and I get an error only when I try to set it. The variable is set as read/write and gives no problems if changed manually from a dashboard.
I also tried changing the way I define switchValue using single/double quotes, the boolean True value, integer 1 and floating point 1.0 but nothing changes.

Any idea on what I am doing wrong?

PROBLEM SOLVED! I was using the Device ID in place of the Thing ID in my requests. For some reason, this allowed me to read values nevertheless.
This is why I got confused, Arduino Cloud allowed me to read data but not to write it. When I set the Thing Id to the correct value I could set variables as I wished.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.