hardbyte / hardbyte/python-can

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

Đang mở
#1,439 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Python
Star
1.6k
Fork
697
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### 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()
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.