hardbyte / hardbyte/python-can

logging level with debug always failed with AttributeError: 'list' object has no attribute 'isalnum'

未关闭
#1,439 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
Python
星标
1.6k
派生
697
PR 合并指标
30 天内没有已合并 PR

描述

### Describe the bug

When setting logging level to debug, each send message will gives above error. It is later found out that

From the can/Message.py line 143, -->if (self.data is not None) and (self.data.isalnum()):

Message.data is a list not a string, therefore above check on second part where it is checking self.data.isalnum() will gives error of AttributeError: 'list' object has no attribute 'isalnum'.

### To Reproduce

enable logging set logging level to debug. then try to send a can message and observe the error.

### Expected behavior

### Additional context

OS and version: window 10
Python version: 3.10
python-can version:
python-can interface/s (if applicable):

Traceback and logs

```python
def __str__(self) -> str:
field_strings = [f"Timestamp: {self.timestamp:>15.6f}"]
if self.is_extended_id:
arbitration_id_string = f"ID: {self.arbitration_id:08x}"
else:
arbitration_id_string = f"ID: {self.arbitration_id:04x}"
field_strings.append(arbitration_id_string.rjust(12, " "))

flag_string = " ".join(
[
"X" if self.is_extended_id else "S",
"Rx" if self.is_rx else "Tx",
"E" if self.is_error_frame else " ",
"R" if self.is_remote_frame else " ",
"F" if self.is_fd else " ",
"BS" if self.bitrate_switch else " ",
"EI" if self.error_state_indicator else " ",
]
)

field_strings.append(flag_string)

field_strings.append(f"DL: {self.dlc:2d}")
data_strings = []
if self.data is not None:
for index in range(0, min(self.dlc, len(self.data))):
data_strings.append(f"{self.data[index]:02x}")
if data_strings: # if not empty
field_strings.append(" ".join(data_strings).ljust(24, " "))
else:
field_strings.append(" " * 24)

if (self.data is not None) and (self.data.isalnum()): <=================== here
field_strings.append(f"'{self.data.decode('utf-8', 'replace')}'")

if self.channel is not None:
try:
field_strings.append(f"Channel: {self.channel}")
except UnicodeEncodeError:
pass

return " ".join(field_strings).strip()
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。