python-2.7 - 在python中的Twython异常中获取错误代码

标签 python-2.7 error-handling twython

我想捕获由于twython中发生异常而导致的错误代码。那怎么办?现在,我只能捕获 protected 帐户的TwythonAuthError,而不能捕获403或404等错误。我想将这些错误代码与发生此错误的用户名一起保存在某个文件中。

最佳答案

您可以使用try/except捕获错误,然后使用.error_code进行访问,如下所示:

try:
    twython.create_friendship(user_id=userID)
except TwythonError as e:
    print e.error_code

关于python-2.7 - 在python中的Twython异常中获取错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34221809/

相关文章:

regex - 从 URL 中删除文件名

python - 重定向到变量值和字符剪切逻辑

python - 在 Linux 上使用 Python 从子进程中杀死父进程

python - 如何将python包安装到指定目录

python - 如何使用 Twython 将图片发布到 Twitter?

python - 如何在python中匹配$(....)中的字符串

ruby - ruby gem 阻止我救援

sql - db2函数中的raise_application_error

Pythonic 处理此错误情况

python - 使用 twython 回复给定的推文