使用 python urllib2.open 时出现 HTTP 500 错误 [英] I get HTTP 500 error when use python urllib2.open

查看:39
本文介绍了使用 python urllib2.open 时出现 HTTP 500 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码就像.网址是我的博客,我想获取和备份我的博客文章.我的其他博文一切顺利,但这篇博文返回 500 错误.

The code is like. The url is my blog and I'd like to fetch and backup my blog posts. Things goes well with my other blog posts but return 500 error with this one.

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

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

Can you help me figure out how to debug a HTTP 500 error?

推荐答案

页面内容加载完毕,返回 500 错误.但是我自己看不懂页面内容是否相关.

A page content is loaded, and a 500 error is returned. But I myself can't read whether the page content is relevant.

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

To avoid error on this specific page or website you could do (WARNING this is not very pretty)

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

这篇关于使用 python urllib2.open 时出现 HTTP 500 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆