twython获取api错误代码

时间:2018-06-11 19:24:18

标签: python twitter exception-handling twython

我正在尝试从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错误代码 261 271 272 ,...它会输出HTTP错误 403 (禁止)。

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

1 个答案:

答案 0 :(得分:0)

如果您使用print(e)打印出所有e,您将获得更多信息。