Skip to content
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

UnboundLocalError: cannot access local variable 'err' where it is not associated with a value , core.py line 948, in _get_socket #402

Closed
simon-kuzin opened this issue Aug 31, 2023 · 3 comments

Comments

@simon-kuzin
Copy link

If connection error occurs XenonDevice._get_socket fails with an exception UnboundLocalError: cannot access local variable 'err' where it is not associated with a value

Stacktrace:
Exception has occurred: UnboundLocalError (note: full exception trace is shown but execution is paused at: _run_module_as_main) cannot access local variable 'err' where it is not associated with a value File "/Users/Simon/Projects/SmartHome/tinytuya/.venv/lib/python3.11/site-packages/tinytuya/core.py", line 948, in _get_socket return err ^^^ File "/Users/Simon/Projects/SmartHome/tinytuya/.venv/lib/python3.11/site-packages/tinytuya/core.py", line 1085, in _send_receive sock_result = self._get_socket(False) ^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/Simon/Projects/SmartHome/tinytuya/.venv/lib/python3.11/site-packages/tinytuya/core.py", line 1845, in set_value data = self._send_receive(payload, getresponse=(not nowait)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/Simon/Projects/SmartHome/tinytuya/.venv/lib/python3.11/site-packages/tinytuya/Contrib/IRRemoteControlDevice.py", line 237, in send_command self.set_value( IRRemoteControlDevice.DP_SEND_IR, json.dumps(command), nowait=True ) File "/Users/Simon/Projects/SmartHome/tinytuya/.venv/lib/python3.11/site-packages/tinytuya/Contrib/RFRemoteControlDevice.py", line 89, in send_command super(RFRemoteControlDevice, self).send_command( mode, data ) ...

Root cause:
in _get_socket
if self.socket is None: # Set up Socket retries = 0 err = ERR_OFFLINE ... except socket.timeout as err: ... err = ERR_OFFLINE except Exception as err: ... err = ERR_OFFLINE

declaration of err in except statement overrides local err

solution rename exception variable in except statements . e.g. except Exception as e:

@jasonacox
Copy link
Owner

Good catch @simon-kuzin ! Thank you!

@jasonacox
Copy link
Owner

Updated in v1.12.11 (pip install --upgrade tinytuya)

Please let us know if this fixes your issue.

@simon-kuzin
Copy link
Author

Issue fixed with 1.12.11. We can close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants