README usage example raises `NameError: name 'subscription_info' is not defined`

未关闭 适合新手
#216 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
documentation

调研方向

在 README 中找到使用示例,并找到 PyPI 页面上对应的示例。按照 issue 中展示的结构,在调用 webpush 之前定义一个有代表性的 subscription_info 对象和数据。确认该示例不再引发 NameError,并展示预期的凭据和请求步骤。

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

描述

The usage example in the README (and the PyPI page) is:

from pywebpush import webpush

webpush(subscription_info,
        data,
        vapid_private_key="Private Key or File Path[1]",
        vapid_claims={"sub": "mailto:YourEmailAddress"})

Copied verbatim into a clean environment it dies immediately, because neither subscription_info nor data is ever defined:

$ pip install pywebpush   # 2.5.0
$ python sample.py
NameError: name 'subscription_info' is not defined

Reproduced 2026-11-21 and re-verified 2026-11-25 (pywebpush 2.5.0, Python 3.12.3). A new user can't tell what shape subscription_info is supposed to have, so the example stops them before the VAPID step it is trying to teach.

Suggested fix — show concrete literals, e.g.:

subscription_info = {
    "endpoint": "https://push.example.com/...",
    "keys": {"p256dh": "...", "auth": "..."},
}
data = "hello from pywebpush"

webpush(subscription_info,
        data,
        vapid_private_key="path/to/private_key.pem",
        vapid_claims={"sub": "mailto:[email protected]"})

That runs through to the actual credential/request step, which is where a first-time user expects to spend their effort.


Found while running the documented quickstarts of 50 APIs from clean environments for a small benchmark (the Quickstart Friction Index — full data and a free sample: https://neoloong.gumroad.com/l/bxpkri). Happy to re-run and confirm once fixed.

主要语言
Python
星标
381
派生
61
平均合并
6 分钟
30 天内合并 PR
1

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

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

web-push-libs/pywebpush 的其他 Issue

查看 web-push-libs/pywebpush 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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