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

"upload --verify" fails when the file contains non-ascii characters #80

Open
MarkMartinec opened this issue Mar 15, 2018 · 1 comment
Open

Comments

@MarkMartinec
Copy link

Using the latest nodemcu-uploader 0.4.3 (serial 3.2.1) from github, Python 2.7.14.

Trying to upload a Lua file containing UTF-8 characters, the nodemcu-uploader fails
when option --verify is used. Without the --verify the upload succeeds (luckily!).

Example file to be uploaded:

function print_pm(pm2_5, pm10)
  local fmt = string.format
  print(fmt("PM2.5: %4.1f μg/m³, PM10: %4.1f μg/m³", pm2_5, pm10))
end
$ nodemcu-uploader.py --port /dev/cuaU1 upload -v sha1 test.lua
opening port /dev/cuaU1 with 115200 baud
Preparing esp for transfer.
Transferring test.lua as test.lua
Verifying using sha1...
Remote SHA1: 6c872418ff59355d196a1762f52ab53b3079318a
Traceback (most recent call last):
  File "nodemcu_uploader/nodemcu-uploader.py", line 11, in <module>
    main.main_func()
  File "nodemcu_uploader/main.py", line 267, in main_func
    args.restart)
  File "nodemcu_uploader/main.py", line 56, in operation_upload
    uploader.write_file(filename, dst, verify)
  File "nodemcu_uploader/uploader.py", line 294, in write_file
    self.verify_file(path, destination, verify)
  File "nodemcu_uploader/uploader.py", line 316, in verify_file
    filehashhex = hashlib.sha1(content.encode(ENCODING)).hexdigest()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 67: ordinal not in range(128)

The python code should be treating the contents of the file to be uploaded as bytes, not trying to attribute a character set to it - and if any at all, it should not be limited to ASCII, but at least to UTF-8. After all, Lua is 8-bit clean as far as strings are concerned, so an uploader should not be posing unnecessary restrictions.

@kmpm
Copy link
Owner

kmpm commented Sep 9, 2020

Some of this will be solved with the drop of support for python 2.7 in the next version

@kmpm kmpm added this to the v1.0.0 milestone Sep 9, 2020
@kmpm kmpm modified the milestones: v1.0.0, future Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants