New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ubus: Refresh session on Access denied #8111
Conversation
@@ -142,6 +165,11 @@ def _req_json_rpc(url, session_id, rpcmethod, subsystem, method, **params): | |||
|
|||
if res.status_code == 200: | |||
response = res.json() | |||
if 'error' in response: | |||
if 'message' in response['error'] and response['error']['message'] == "Access denied": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (98 > 79 characters)
|
||
self.parse_api_pattern = re.compile(r"(?P<param>\w*) = (?P<value>.*);") | ||
self.lock = threading.Lock() | ||
self.last_results = {} | ||
self.url = 'http://{}/ubus'.format(host) | ||
|
||
self.session_id = _get_session_id(self.url, username, password) | ||
self.session_id = _get_session_id(self.url, self.username, self.password) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (81 > 79 characters)
except PermissionError: | ||
_LOGGER.warn("Invalid session detected." + | ||
" Tryign to refresh session_id and re-run the rpc") | ||
self.session_id = _get_session_id(self.url, self.username, self.password) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (85 > 79 characters)
return fn(self, *args, **kwargs) | ||
except PermissionError: | ||
_LOGGER.warn("Invalid session detected." + | ||
" Tryign to refresh session_id and re-run the rpc") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
Wops. Managed to screw up creating the PR. From the wrong branch and to the wrong branch. Tried to fix it upp but sorry for the noise. |
def _refresh_on_acccess_denied(func): | ||
"""If remove rebooted, it lost our session so rebuld one and try again.""" | ||
# {'error': {'message': 'Access denied', 'code': -32002}, | ||
# 'id': 1, 'jsonrpc': '2.0'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please cleanup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
except PermissionError: | ||
_LOGGER.warning("Invalid session detected." + | ||
" Tryign to refresh session_id and re-run the rpc") | ||
self.session_id = _get_session_id(self.url, self.username, self.password) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (85 > 79 characters)
When a openwrt router reboots, all the session ids gets invalidated. In that case we need to log in again and get a new session id. Signed-off-by: Anton Lundin <glance@acc.umu.se>
Back in "ubus: Refresh session on Access denied (home-assistant#8111)" I added the decorator _refresh_on_acccess_denied. Somehow that stopped multiple ubus trackers from working in parallel, and only the one first init'ed worked. Changing the order of the decorators fixes the issue but, I'm sorry to say I can't figure out why. There's some magic somewhere which I'm missing. Signed-off-by: Anton Lundin <glance@acc.umu.se>
Back in "ubus: Refresh session on Access denied (#8111)" I added the decorator _refresh_on_acccess_denied. Somehow that stopped multiple ubus trackers from working in parallel, and only the one first init'ed worked. Changing the order of the decorators fixes the issue but, I'm sorry to say I can't figure out why. There's some magic somewhere which I'm missing. Signed-off-by: Anton Lundin <glance@acc.umu.se>
Back in "ubus: Refresh session on Access denied (#8111)" I added the decorator _refresh_on_acccess_denied. Somehow that stopped multiple ubus trackers from working in parallel, and only the one first init'ed worked. Changing the order of the decorators fixes the issue but, I'm sorry to say I can't figure out why. There's some magic somewhere which I'm missing. Signed-off-by: Anton Lundin <glance@acc.umu.se>
When a openwrt router reboots, all the session ids gets invalidated. In that case we need to log in again and get a new session id. Signed-off-by: Anton Lundin <glance@acc.umu.se>
Back in "ubus: Refresh session on Access denied (home-assistant#8111)" I added the decorator _refresh_on_acccess_denied. Somehow that stopped multiple ubus trackers from working in parallel, and only the one first init'ed worked. Changing the order of the decorators fixes the issue but, I'm sorry to say I can't figure out why. There's some magic somewhere which I'm missing. Signed-off-by: Anton Lundin <glance@acc.umu.se>
When a openwrt router reboots, all the session ids gets invalidated.
In that case we need to log in again and get a new session id.
Signed-off-by: Anton Lundin glance@acc.umu.se