Hi community, i got an error while running my microservice in cumulocity iot and i am not able to understand what is the main issue here need suggestions …
error :
Exception in thread Thread-1:
Traceback (most recent call last):
File “/usr/local/lib/python3.9/threading.py”, line 980, in _bootstrap_inner
self.run()
File “/usr/local/lib/python3.9/threading.py”, line 917, in run
self._target(*self._args, **self._kwargs)
File “/usr/local/lib/python3.9/site-packages/c8y_tk/notification2/listener.py”, line 256, in listen
self._event_loop.run_until_complete(self._listener.listen(_callback))
File “/usr/local/lib/python3.9/asyncio/base_events.py”, line 647, in run_until_complete
return future.result()
File “/usr/local/lib/python3.9/site-packages/c8y_tk/notification2/listener.py”, line 130, in listen
c = await self._get_connection()
File “/usr/local/lib/python3.9/site-packages/c8y_tk/notification2/listener.py”, line 88, in _get_connection
token = self.c8y.notification2_tokens.generate(self.subscription_name, expires=2)
File “/usr/local/lib/python3.9/site-packages/c8y_API/model/notification2.py”, line 246, in generate
token_json = self.c8y.post(self.resource + ‘/token’, td_json)
File “/usr/local/lib/python3.9/site-packages/c8y_API/_base_API.py”, line 194, in post
raise ValueError(f"Unable to perform POST request. Status: {r.status_code} Response:\n" + r.text)
ValueError: Unable to perform POST request. Status: 403 Response:
{“error”:“security/Forbidden”,“message”:“Access is denied”,“info”:“Getting Started - Cumulocity IoT Guides”}
Without looking further into it, it seems that you don’t have sufficient permissions to use this API endpoint. So, to be able to use Notification 2.0 the microservice user needs ROLE_NOTIFICATION_2_ADMIN for example.
Hi Christoph. We had two both staging and prod tenant. We were able to have the microservice loaded and work on staging but not prod. Both has 1018.540.142. Both has not special permission specified in the permission tab of the microservice. The only observable difference is I see in prod compared to staging is that the US is different. Staging has UI 1009.0.12 and prod has 1.0.1 UI. Do I still need to explicitly add the ROLE_NOTIFICATION_2_ADMIN?
UI should be unrelated, but if you want to use Notification 2.0 you’d need that permission. In your setup I’d be rather puzzled why it worked on your staging environment in the first place.
Christoph is correct, the Notifications 2.0 token API requires the user requesting the token to have the ROLE_NOTIFICATION_2_ADMIN role: Cumulocity IoT - OpenAPI Specification. As a side note, while we can guess what happened from the stack trace you posted, sharing at least the relevant parts of your code, and being clear about what request failed, makes it much easier for people to assist. For example, in a typical Notifications 2.0 application you would have made a subscription request before creating the token. Is that the case here and did that request succeed?
I will get the information for you after I get a chance to talk to my developer. What I know is that the functionality we were implementing works in our staging tenant.