You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Win10 Toast通知报错:WPARAM为NoneType及WNDPROC返回值转换问题

排查方向与修复建议

针对你遇到的WNDPROC return value cannot be converted to LRESULT和TypeError: WPARAM is simple, so must be an int object (got NoneType)报错,从代码逻辑和win10toast底层运行机制出发,排查方向如下:

  • 避免重复创建ToastNotifier实例
    你的代码在循环中每次都新建ToastNotifier()对象,频繁创建实例会导致Windows通知API的资源冲突,引发参数传递错误。应该只初始化一次实例,复用它来显示通知。

  • 处理loadrss返回None的边界情况
    循环中重新调用loadrss(user_in)时,可能因赛事结束或RSS内容更新,导致get_rss变为None,将None传递给show_toast的消息参数会触发底层类型错误,必须在显示通知前判断get_rss是否有效。

  • 检查threaded=True的线程冲突
    使用threaded=True时,通知会在后台线程运行,如果上一个通知未结束就触发新通知,可能导致线程间Windows消息处理混乱。可以在显示新通知前,调用toast_notifier.notification_active()检查是否有活跃通知,等待其结束后再显示新通知。

  • 验证图标路径有效性
    相对路径'Cricket.ico'可能因程序运行目录问题无法被找到,导致通知初始化出错。可以换成绝对路径,或者暂时去掉icon_path参数测试是否是图标引发的问题。

  • 升级win10toast版本
    旧版本的win10toast存在Windows消息处理的bug,执行pip install --upgrade win10toast更新到最新版,可能直接解决该报错。


修改后的示例代码

import requests 
import feedparser
from time import sleep
from win10toast import ToastNotifier

def user_input():
    team = str(input("enter team name: "))
    return team

def loadrss(team_name):
    xml_score = feedparser.parse("https://static.cricinfo.com/rss/livescores.xml")
    for entry in xml_score.entries:
        if team_name in entry.title:
            return entry.description
    return None

if __name__ == '__main__':
    user_in = user_input()
    # 只初始化一次ToastNotifier实例
    toast_notifier = ToastNotifier()
    
    while True:
        get_rss = loadrss(user_in)
        if not get_rss:
            message = f"Team {user_in.upper()} Not playing or match ended"
        else:
            message = get_rss
        
        # 等待上一个通知结束后再显示新通知
        while toast_notifier.notification_active():
            sleep(1)
        
        toast_notifier.show_toast(
            "Cricket update",
            message,
            icon_path='Cricket.ico',  # 建议替换为绝对路径
            duration=10,
            threaded=True
        )
        sleep(30)

内容的提问来源于stack exchange,提问作者Aditya V

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 09:45:34