Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Why is the same code not running now?

未关闭
#1,862 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
python
领域
embedded-iot

调研方向

首先,使用所述的 Canable 硬件、slcan 接口、操作系统、Python 版本和 python-can 版本重现所提供的脚本。检查 can.interface.Bus 和 AsyncBufferedReader 入口点,并收集缺失的 traceback 或日志。完成标准是确定一个可重现的原因并提供可执行的报告,或记录该问题属于环境问题而不是 python-can 的 bug。

由索引模型根据 Issue 内容生成。

描述

bug
Describe the bug

I used to be able to successfully obtain data using the following code, but now the data cannot be displayed
The hardware I am using is Canable.

Additional context

OS and version:Windows10/Ubuntu 24.04
Python version:Python3.10/Python3.12
python-can version:4.2.0/4.4.2
python-can interface/s (if applicable):slcan

Traceback and logs

The environment that was once able to run successfully:

cantools==39.3.0
mqtt==0.0.1
paho-mqtt==1.6.1
pyserial==3.5
python-can==4.2.0

this is my code example,It was once able to run successfully.

# This is a sample Python script.
import asyncio
import time
from typing import List

import can
from can.notifier import MessageRecipient
# import cantools
import serial.tools.list_ports

# import paho.mqtt.client as mqtt
# import json

# client = mqtt.Client()
# db = cantools.database.load_file('.\wuling.dbc')


def on_connect(client, userdata, flags, rc):
    print(f"Connected with result code {rc}")


async def main() -> None:
    port = None
    ports_list = list(serial.tools.list_ports.comports())
    if len(ports_list) <= 0:
        print("无串口设备,即将退出...")
        time.sleep(2)
        exit(0)
    else:
        print("可用的串口设备如下:")
        for comport in ports_list:
            print(comport.name + ",描述:" + str(comport.description) + ",设备ID:" + str(comport.vid) + ":" + str(
                comport.pid))

        for comport in ports_list:
            if comport.pid == 4478 and comport.vid == 5840:
                print("选择第一个CAN设备:" + comport.name + " " + str(comport.description))
                port = comport
                break

    if port is None:
        print("未发现CAN设备,即将退出...")
        time.sleep(2)
        exit(0)

    # client.on_connect = on_connect
    # client.username_pw_set(username="user", password="user")
    # client.connect("127.0.0.1", 1883, 60)
    """The main function that runs in the loop."""

    with can.interface.Bus(bustype='slcan', channel=str(port.name), bitrate=500000, ) as bus:
        reader = can.AsyncBufferedReader()
        listeners: List[MessageRecipient] = [
            reader,
        ]
        loop = asyncio.get_running_loop()
        notifier = can.Notifier(bus, listeners, loop=loop)
        while True:
            msg = await reader.get_message()
            try:
                print(msg)
            except Exception as ex:
                print(ex)
                pass
            pass


if __name__ == "__main__":
    asyncio.run(main())

主要语言
Python
星标
1.6k
派生
697
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

hardbyte/python-can 的其他 Issue

查看 hardbyte/python-can 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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