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?