【发布时间】:2015-08-11 08:02:04
【问题描述】:
以下问题
我确实有一个 python 脚本正在运行并执行 HTTP 请求。 有时我会遇到几个错误,例如 http 400。现在我想记录这些错误并中断脚本停止工作。
import logging
date = .strftime().....
try:
script X
except:
error = urllib2.HTTPError
errorcode = error.code
file = open ("error.txt",'r+')
file.write("Error Code: %s, date \n", errorcode)
file.close()
pass
对吗?还是我做错了什么。我应该对 HTTP 错误使用 If 吗?
这会阻止脚本在出错时停止 -> 通过
谢谢!
【问题讨论】:
-
为什么不能自己尝试一下?
标签: python http logging error-handling