python-3.x - 如何管理 Python 中的 twitch API 错误?

标签 python-3.x api error-handling http-error twitch-api

我正在使用 twitch api(twitch-python 和 python-twitch-client)来抓取 twitch。

我不知道应该如何管理这些 httperrors,因为我没有使用 urllib.request。

    game = []

    for a in lis[68:]:
        b = client.videos.get_by_id(a).game

        try:


            game.append(b)
        except Exception as e:
            print(type(e))

即使我使用 except,这个错误仍然出现: HTTPError:404 客户端错误:未找到 url:https://api.twitch.tv/kraken/videos/420146641

最佳答案

好吧,我想我知道问题出在哪里了。您没有在 try 子句中包装正确的代码。 .append 不太可能引发错误,因此当您将 b 分配给某些错误抛出函数的输出时,可能会发生错误。将 for 循环后的第一行代码移至 try block 中。

关于python-3.x - 如何管理 Python 中的 twitch API 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56881234/

相关文章:

事务中的 MySQL 回滚

python - 用一串数字生成加法、减法或什么都不加的变化,以达到 100

用于构建 API 的 JavaScript 文件

c - 仅在 C 中公开必需的函数

ios - 发送同步请求 :urlrequest returningResponse:&responce error:&error is unavilable in WatchOS2

node.js - Node 进程即使在使用时也存在

python - 使用 GroupBy 查找 DataFrame 中的最小值

python - tkinter 列表框和标签位置

python - 如何在 Python3 中添加带有标志的命令行参数?

r - 从github安装flipMaxDiff软件包时出错