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

[ssh] Decoding the output of the sysupgrade command fails with UnicodeDecodeError #370

Closed
okraits opened this issue Jan 21, 2021 · 2 comments · Fixed by #372
Closed

[ssh] Decoding the output of the sysupgrade command fails with UnicodeDecodeError #370

okraits opened this issue Jan 21, 2021 · 2 comments · Fixed by #372

Comments

@okraits
Copy link
Member

okraits commented Jan 21, 2021

I did a firmware upgrade with openwisp-firmware-upgrader. It was successful, but I got the following exception twice:

Traceback (most recent call last):
  File "/home/okraitschy/owm_new/build/venv/lib/python3.7/site-packages/billiard/process.py", line 327, in _bootstrap        
    self.run()                                         
  File "/home/okraitschy/owm_new/build/venv/lib/python3.7/site-packages/billiard/process.py", line 114, in run                
    self._target(*self._args, **self._kwargs)
  File "/home/okraitschy/owm_new/build/venv/lib/python3.7/site-packages/openwisp_firmware_upgrader/upgraders/openwrt.py", line
 134, in upgrade                                                                                                             
    conn.exec_command(command, timeout=timeout)                                                                              
  File "/home/okraitschy/owm_new/build/venv/lib/python3.7/site-packages/openwisp_controller/connection/connectors/ssh.py", line 136, in exec_command
    output = output_str.decode('utf8').strip()  
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 6586: invalid continuation byte

Due to sysupgrade -v, the verbose output of sysupgrade is decoded and that fails because of some byte.

https://github.com/openwisp/openwisp-controller/blob/master/openwisp_controller/connection/connectors/ssh.py#L136

Just some thoughts:

Why do we print out the output?
Why do we decode it?
Why don't we catch exceptions there?

@nemesifier
Copy link
Member

@okraits:

Why do we print out the output?

if I remember correctly, print is used for logging and could be changed to logger.info()

Why do we decode it?

I don't remember now, it may be that the returned value is byte. Not sure.

Why don't we catch exceptions there?

I didn't account for this failure.

@okraits
Copy link
Member Author

okraits commented Jan 21, 2021

if I remember correctly, print is used for logging and could be changed to logger.info()

Yeah, I was also thinking about converting this to logging.

I don't remember now, it may be that the returned value is byte. Not sure.

I will have a look into it.

I didn't account for this failure.

I didn't mean that as an accusation. Thank you for your great work!

I'll try to come up with a PR for this.

@okraits okraits self-assigned this Jan 21, 2021
okraits added a commit to TDT-AG/openwisp-controller that referenced this issue Jan 23, 2021
okraits added a commit to TDT-AG/openwisp-controller that referenced this issue Jan 24, 2021
okraits added a commit to TDT-AG/openwisp-controller that referenced this issue Jan 24, 2021
@nemesifier nemesifier added the bug label Jan 25, 2021
@nemesifier nemesifier added this to Backlog in OpenWISP Priorities for next releases via automation Jan 25, 2021
@nemesifier nemesifier moved this from Backlog to In progress in OpenWISP Priorities for next releases Jan 25, 2021
okraits added a commit to TDT-AG/openwisp-controller that referenced this issue Jan 25, 2021
@okraits okraits moved this from In progress to Ready for review/testing in OpenWISP Priorities for next releases Jan 25, 2021
OpenWISP Priorities for next releases automation moved this from Ready for review/testing to Done Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants