-
-
Notifications
You must be signed in to change notification settings - Fork 230
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
AttributeError: 'bytes' object has no attribute 'encode' #1140
Comments
are you editing some attributes before saving the file? |
What I do is I go through multiple mf4 files and just looking for the signals I need by name. The only attribute I edit of the mf4 file is the start_time as I need them to be concaded into one at the end and it's important that the timestamps line up. Here the code before the saving for ease of understanding `
` |
which asammdf version do you use? |
I use version 8.0.1 |
@MeYa2111 please try the development branch code |
Hello,
I don´t know if this issue has been fixed with newer versions and I´m not the best when it comes to coding, however when trying to save mdf_safe.save() it will sometimes throw you the error code:
\Python\Python39\site-packages\asammdf\blocks\v4_blocks.py", line 6332, in to_blocks
text=text.encode("utf-8", "replace"),
AttributeError: 'bytes' object has no attribute 'encode'
I dont know if its just human Error of mine, but I found easy fix by changing that to_blocks() function with :
if text: if text in defined_texts: self.name_addr = defined_texts[text] else: if isinstance(text, bytes): text = text.decode("utf-8", "replace") text = text.encode("utf-8", "replace") tx_block = TextBlock( text = text, meta=False, safe=True, ) self.name_addr = address defined_texts[text] = address tx_block.address = address address += tx_block.block_len blocks.append(tx_block) else: self.name_addr = 0
or by simply replacing the whole function with
`
def to_blocks(
self,
address: int,
blocks: list[Any],
defined_texts: dict[str, int],
si_map: dict[bytes, int],
) -> int:
id_ = id(self)
if id_ in si_map:
return address
`
I hope this isn´t old news. Sorry if something is wrong its my first issue post on Github
The text was updated successfully, but these errors were encountered: