使用python urllib2.open时出现HTTP 500错误

时间:2011-12-06 18:33:40

标签: python urllib2

代码就像。网址是我的博客,我想获取并备份我的博文。我的其他博客文章的情况很顺利,但这个问题返回500错误。

usock = urlopen("http://xiaoshuaistudio.ycool.com/post.4606754.html")
htmlSource = usock.read()
usock.close()

您能帮我弄清楚如何调试HTTP 500错误吗?

3 个答案:

答案 0 :(得分:2)

加载页面内容,并返回500错误。但我自己无法读取页面内容是否相关。

为了避免您在此特定页面或网站上出错(警告,这不是很漂亮)

try:
  response = urlopen(url)
  content = response.read()
except HTTPError, e:
  if e.getcode() == 500:
    content = e.read()
  else:
    raise

答案 1 :(得分:0)

查看Web服务器上的服务器日志。通常,错误数据在服务器上是安全的。将错误日志转储给用户并不是一个好主意。

答案 2 :(得分:0)

我认为ycool.com服务器出了问题,因为我无法使用网络浏览器打开此网址。

http://xiaoshuaistudio.ycool.com/post.4606754.html

对于某些网址,该网络服务器将始终返回status code 500 Internal Server Error,该网址应为200 OK

如果urlopen函数仅检查状态代码,它将返回该错误(尽管服务器发送该页面的内容)。