ulptool icon indicating copy to clipboard operation
ulptool copied to clipboard

fsys.write() expecting string but parameter is byte

Open swaraj429 opened this issue 4 years ago • 13 comments

platform: linux python 2.7.16 Traceback (most recent call last): File "/home/swaraj/.arduino15/packages/esp32/tools/ulptool/src/esp32ulp_build_recipe.py", line 503, in main(sys.argv[1:]) File "/home/swaraj/.arduino15/packages/esp32/tools/ulptool/src/esp32ulp_build_recipe.py", line 102, in main build_ulp(PATHS, ulp_files, board_options, True) File "/home/swaraj/.arduino15/packages/esp32/tools/ulptool/src/esp32ulp_build_recipe.py", line 230, in build_ulp fsym.write(out) TypeError: write() argument must be str, not bytes exit status 1 Error compiling for board ESP32 Dev Module.

swaraj429 avatar May 11 '20 04:05 swaraj429

I have a similar error. Platform:linux Python:3.7.7 Esp core:1.0.4

Traceback (most recent call last): File "/home/paulo/.arduino15/packages/esp32/tools/ulptool/src/esp32ulp_build_recipe.py", line 560, in main(sys.argv[1:]) File "/home/paulo/.arduino15/packages/esp32/tools/ulptool/src/esp32ulp_build_recipe.py", line 106, in main build_ulp(PATHS, ulp_files, board_options, True) File "/home/paulo/.arduino15/packages/esp32/tools/ulptool/src/esp32ulp_build_recipe.py", line 160, in build_ulp error_string = cmd[0] + '\r' + err TypeError: can only concatenate str (not "bytes") to str

PauloFernandoSF avatar May 29 '20 13:05 PauloFernandoSF

@swaraj429 I'm not sure whats the issue can you post the whole error you are seeing?

@PauloFernandoSF only python 2.7 is supported currently, can you use that instead and report back any errors?

duff2013 avatar May 29 '20 16:05 duff2013

Thanks, i've changed do Python 2.7 and worked!

PauloFernandoSF avatar May 29 '20 16:05 PauloFernandoSF

I've modified script - now it works with python 3.

This particular error corrected in line 233 - file 'fsym' should be open in binary mode: with open(file_names_constant['sym'],"wb") as fsym: OR in line 234 by converting 'out' to string: fsym.write(out.decode("utf-8"))

O1dAlex avatar May 30 '20 07:05 O1dAlex

@swaraj429 I'm not sure whats the issue can you post the whole error you are seeing? @PauloFernandoSF only python 2.7 is supported currently, can you use that instead and report back any errors?

that's all the error I got

swaraj429 avatar Jun 01 '20 16:06 swaraj429

@swaraj429,

In the platform.local.txt (read the readme to find its location), could you change python to python2:

## ulp build tool
compiler.s.cmd=python "{tools.ulptool.path}{tools.ulptool.cmd}"

to:

## ulp build tool
compiler.s.cmd=python2 "{tools.ulptool.path}{tools.ulptool.cmd}"

I think in the newest Linux version, python is actually Python 3.

Regards, Vincent

Vincent-Stragier avatar Nov 13 '20 22:11 Vincent-Stragier

Having the same issue as @PauloFernandoSF had right now. Python 3.8.5, 1.0.6 core, Arduino 1.8.13, Win. Gonna downgrade Python to 2.7 and check again.

UPD. Yep, fixed on Python 2.7.18

nightlyteacups avatar Mar 27 '21 16:03 nightlyteacups

I'm observing a similar issue when there is an ASM compile issue. Like typo or other problem. The compiler is not reporting where and what bug you have in the code, but instead: TypeError: can only concatenate str (not "bytes") to str

yeckel avatar May 05 '21 09:05 yeckel

I'm observing a similar issue when there is an ASM compile issue. Like typo or other problem. The compiler is not reporting where and what bug you have in the code, but instead: TypeError: can only concatenate str (not "bytes") to str

It's probably the still issue. Which version of Python are you using? And can you paste the full error code?

Vincent-Stragier avatar May 05 '21 10:05 Vincent-Stragier

Python 3.8.5 at Ubuntu 20.04, I've added "hi" into the ASM code:

Traceback (most recent call last):
  File "/home/libor/.arduino15/packages/esp32/tools/ulptool/src/esp32ulp_build_recipe.py", line 560, in <module>
    main(sys.argv[1:])
  File "/home/libor/.arduino15/packages/esp32/tools/ulptool/src/esp32ulp_build_recipe.py", line 106, in main
    build_ulp(PATHS, ulp_files, board_options, True)
  File "/home/libor/.arduino15/packages/esp32/tools/ulptool/src/esp32ulp_build_recipe.py", line 140, in build_ulp
    error_string = cmd[0] + '\r' + err
TypeError: can only concatenate str (not "bytes") to str
exit status 1
Error compiling for board TTGO LoRa32-OLED V1.

yeckel avatar May 05 '21 10:05 yeckel

Can you change the err to err.decode('utf-8') at the line 140 in the file "/home/libor/.arduino15/packages/esp32/tools/ulptool/src/esp32ulp_build_recipe.py"? From what I see, err is a bytes array.

Vincent-Stragier avatar May 05 '21 10:05 Vincent-Stragier

Sure, and it helped!

adc.ulp.pS: Assembler messages:/esp32/tools/ulptool/src/esp32ulp-elf-binutils/bin/esp32ulp-elf-as -al=adc.ulp.lst -W -o adc.ulp.o adc.ulp.pS
adc.ulp.pS:19: Error: syntax error. Input text was hi.
adc.ulp.pS:19: Error: 

exit status 1
Error compiling for board ESP32 Wrover Module.

probably all 4 remaining error_string = cmd[0] + '\r' + err could be changed too.

yeckel avatar May 05 '21 11:05 yeckel

Glad it helped. And yes, the remaining lines can be changed.

Vincent-Stragier avatar May 05 '21 11:05 Vincent-Stragier