The purpose of the code is to create a graph for the decision tree model.
The code is given below.
dot_data=StringIO()
tree.export_graphviz(clf,out_file=dot_data)
graph=py.graph_from_dot_data(dot_data.getvalue())
print(graph)
Image.open(graph.create_png(),mode='r')
On execution, it gives the following error:
Traceback (most recent call last):
File "C:/Ankur/Python36/Python Files/Decision_Tree.py", line 58, in <module>
Image.open(graph.create_png(),mode='r')
File "C:\Ankur\Python36\lib\site-packages\PIL\Image.py", line 2477, in open
fp = builtins.open(filename, "rb")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0:
invalid start byte
I am having a hard time to resolve this error as I don't understand it.
create_png() returns a bytes object while Image.open (from PIL) expects a filename or file object.
Try
import io
Image.open(io.BytesIO(graph.create_png()))
and it should work
Related
I am trying to read core dump info that will be saved in flash.
i am first reading the coredump paritition:
esptool.py --port /dev/ttyUSB0 read_flash 0x3ec000 0xE000 ./core.bin
Then I am trying to extract the info using:
espcoredump.py info_corefile --core ./core.bin --core-format raw build/httpsOTA_S_FE.elf
But the script is giving me the following error:
`
espcoredump.py v0.4-dev
===============================================================
==================== ESP32 CORE DUMP START ====================
Traceback (most recent call last):
File "/home/praveen/opt/esp/idf-4.4.2/esp-idf/components/espcoredump/espcoredump.py", line 350, in <module>
temp_core_files = info_corefile()
File "/home/praveen/opt/esp/idf-4.4.2/esp-idf/components/espcoredump/espcoredump.py", line 170, in info_corefile
gdb = EspGDB(gdb_tool, [rom_sym_cmd], core_elf_path, args.prog, timeout_sec=args.gdb_timeout_sec)
File "/home/praveen/opt/esp/idf-4.4.2/esp-idf/components/espcoredump/corefile/gdb.py", line 45, in __init__
self._gdbmi_run_cmd_get_responses(cmd='-data-list-register-values x pc',
File "/home/praveen/opt/esp/idf-4.4.2/esp-idf/components/espcoredump/corefile/gdb.py", line 63, in _gdbmi_run_cmd_get_responses
more_responses = self.p.get_gdb_response(timeout_sec=0, raise_error_on_timeout=False)
File "/home/praveen/.espressif/python_env/idf4.4_py3.10_env/lib/python3.10/site-packages/pygdbmi/gdbcontroller.py", line 269, in get_gdb_response
self.verify_valid_gdb_subprocess()
File "/home/praveen/.espressif/python_env/idf4.4_py3.10_env/lib/python3.10/site-packages/pygdbmi/gdbcontroller.py", line 175, in verify_valid_gdb_subprocess
raise NoGdbProcessError(
pygdbmi.gdbcontroller.NoGdbProcessError: gdb process has already finished with return code: 127
`
My end goal is to get send this partition data to my server and debug the info on server. I first wanted to see the process on the host machine and then implement same on my server.
espcoredump.py info_corefile --core ./core.bin --core-format raw build/httpsOTA_S_FE.elf
is supposed to print the core dump info.
I tried the same with a litle older version of idf IDF-4.2.4 and i get following error:
`
espcoredump.py v0.4-dev
===============================================================
==================== ESP32 CORE DUMP START ====================
Traceback (most recent call last):
File "/home/praveen/opt/esp/idf-4.2.4/esp-idf/components/espcoredump/espcoredump.py", line 1818, in <module>
main()
File "/home/praveen/opt/esp/idf-4.2.4/esp-idf/components/espcoredump/espcoredump.py", line 1813, in main
operation_func(args)
File "/home/praveen/opt/esp/idf-4.2.4/esp-idf/components/espcoredump/espcoredump.py", line 1644, in info_corefile
p,task_name = gdbmi_freertos_get_task_name(p, extra_info[0])
File "/home/praveen/opt/esp/idf-4.2.4/esp-idf/components/espcoredump/espcoredump.py", line 1543, in gdbmi_freertos_get_task_name
p,res = gdbmi_data_evaluate_expression(p, "(char*)((TCB_t *)0x%x)->pcTaskName" % tcb_addr)
File "/home/praveen/opt/esp/idf-4.2.4/esp-idf/components/espcoredump/espcoredump.py", line 1539, in gdbmi_data_evaluate_expression
p = gdbmi_cmd_exec(p, handlers, "-data-evaluate-expression \"%s\"" % expr)
File "/home/praveen/opt/esp/idf-4.2.4/esp-idf/components/espcoredump/espcoredump.py", line 1493, in gdbmi_cmd_exec
p.stdin.write(bytearray("%s\n" % gdbmi_cmd, encoding='utf-8'))
BrokenPipeError: [Errno 32] Broken pipe
`
I've been having a problem lately where I can't access the value of any variable through their name. It's not a connection problem since I can read the value from the read() function just fine. However whenever I use the read_by_name function there's always the same error pyads.pyads_ex.ADSError: ADSError: Unknown Error (857212673).
Because it's an unknown error I haven't been able to find documentation on it. I'm using a BC9120 as a PLC and TwinCat 2. Does anyone know what might be causing this?
Code:
if self.plc.is_open == False:
self.plc.open()
print(self.plc.read(pyads.INDEXGROUP_MEMORYBIT, 0*8 + 0, pyads.PLCTYPE_BOOL))
print(self.plc.read_by_name("Test.M0", pyads.PLCTYPE_BOOL))
Logs:
False
Traceback (most recent call last):
File "c:\Users\MAP9AV\Documents\Banca\Modelo Preditivo\Thread_Sup.py", line 50, in run
print(self.plc.read_by_name("Test.M0", pyads.PLCTYPE_BOOL))
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\connection.py", line 540, in read_by_name
return adsSyncReadByNameEx(
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\pyads_ex.py", line 1154, in adsSyncReadByNameEx
handle = adsGetHandle(port, address, data_name)
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\pyads_ex.py", line 890, in adsGetHandle
handle = adsSyncReadWriteReqEx2(
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\pyads_ex.py", line 774, in adsSyncReadWriteReqEx2
raise ADSError(err_code)
pyads.pyads_ex.ADSError: ADSError: Unknown Error (857212673).
I want to debug Rust with VS Code. I have installed LLDB 6.0.0 and Rust 1.27.1 but I can't debug Rust code with LLDB:
Display settings: variable format=auto, show disassembly=auto, numeric pointer values=off, container summaries=on.
Internal debugger error:
Traceback (most recent call last):
File "/home/kwebi/.vscode/extensions/vadimcn.vscode-lldb-0.8.9/adapter/debugsession.py", line 1365, in handle_message
result = handler(args)
File "/home/kwebi/.vscode/extensions/vadimcn.vscode-lldb-0.8.9/adapter/debugsession.py", line 385, in DEBUG_setBreakpoints
file_id = os.path.normcase(from_lldb_str(source.get('path')))
File "/home/kwebi/.vscode/extensions/vadimcn.vscode-lldb-0.8.9/adapter/__init__.py", line 8, in <lambda>
from_lldb_str = lambda s: s.decode('utf8', 'replace')
File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 12-13: ordinal not in range(128)
I'm using DictWriter to write a dictionary to a csv after some geolocation work.
location = geolocator.reverse(coords)
row["address"] = location.address
writer.writerow(row)
Which generates this:
File "C:\bin64\python\3.4.3\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u200e' in
position 118: character maps to <undefined>
My problem was in how I was opening the file. I suppose I should have posted that in the question. I needed to set the encoding upon opening the file.
with open('results.csv', mode='w', encoding='utf-8', newline='') as file:
...
I'm using Python 3.3 / PyGObject 3.14 in Windows 7 and I have the following problem: Using either gi.repository.GLib.utf8_collate_key and gi.repository.GLib.utf8_collate_key with a non-ascii-only string always results in an UnicodeDecodeError.
Test case:
>from gi.repository import GLib
>asciiText = "a"
>unicodeText = "á"
>asciiText.decode()
b'a'
>unicodeText.decode()
b'\xc3\xa1'
>GLib.utf8_collate_key(asciiText, -1)
'Aa'
>GLib.utf8_collate_key(unicodeText, -1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 1: unexpect
ed end of data
Expected result (from Linux)
>GLib.utf8_collate_key(asciiText, -1)
'a'
>GLib.utf8_collate_key(unicodeText, -1)
'á'
The Windows system's locale is set to Portuguese (Brazil).
Does anybody knows how to solve this? I'm considering rolling my own collating function if I can't get this to work.