【问题标题】:twython get api error codetwython获取api错误码
【发布时间】:2018-06-12 03:35:15
【问题描述】:

我正在尝试从 Twitter API 获取异常代码(使用 twython),但它返回的是 HTTP 错误代码。

Here你可以看到来自twitter API的代码。

例如:

try:
    twitter.retweet(id=tweet["id"])      
except TwythonError as e:     
    print("FAILED to retweet: [tweet_id:" + str(tweet["id"]) + "]")
    print(e.error_code)

以下打印 HTTP 错误代码而不是 twitter API 代码

print(e.error_code)

例如,代替 API 错误代码 261271, 272,... 它会打印 HTTP 错误 403(禁止)。

这是一个问题,因为我无法区分共享相同 HTTP 错误代码的代码。

【问题讨论】:

    标签: python twitter exception-handling twython


    【解决方案1】:

    如果你用print(e)打印出所有的e,你会得到额外的信息。

    【讨论】:

    • 我知道。但我想获取 api 错误代码,以便我可以根据代码处理错误。我不想只打印解释错误的错误字符串。
    猜你喜欢
    • 2016-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 1970-01-01
    • 2017-12-06
    • 2013-06-10
    相关资源
    最近更新 更多