Skip to content
This repository has been archived by the owner on Jan 26, 2025. It is now read-only.

python3 'exec' command str/byte type issue #96

Open
geedubess opened this issue Feb 5, 2021 · 0 comments
Open

python3 'exec' command str/byte type issue #96

geedubess opened this issue Feb 5, 2021 · 0 comments

Comments

@geedubess
Copy link

geedubess commented Feb 5, 2021

Trying to exec a local file on the target via 'exec' command seems to fail on Python 3.8.5.

$ nodemcu-uploader.py exec /tmp/tmp.yYUKAPNw0b/lfs-init.lua

opening port /dev/ttyUSB0 with 115200 baud                    
Execute XXX.lua
Traceback (most recent call last):           
  File "XXX/nodemcu-uploader_src/nodemcu-uploader.py", line 11, in <module>
    main.main_func()                                     
  File "XXX/nodemcu-uploader_src/nodemcu_uploader/main.py", line 334, in main_func
    uploader.exec_file(path)    
  File "XXX/nodemcu-uploader_src/nodemcu_uploader/uploader.py", line 367, in exec_file
    content = from_file(path).replace('\r', b'').split('\n')  
TypeError: a bytes-like object is required, not 'str'

This makes sense to me, as strings are given to replace(), split(), rstrip(), etc...

def from_file(path):
    """Returns content of file as 'bytes'.

Locally, I'm using a patch, which allows it to work as expected, though I haven't tested it extensively:

--- a/nodemcu_uploader/uploader.py
+++ b/nodemcu_uploader/uploader.py
@@ -360,7 +360,7 @@ class Uploader(object):
         filename = os.path.basename(path)
         log.info('Execute %s', filename)
 
-        content = from_file(path).replace('\r', '').split('\n')
+        content = from_file(path).decode('utf-8').replace('\r', '').split('\n')
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant