I get HTTP 500 error when use python urllib2.open

こ雲淡風輕ζ 提交于 2020-01-15 11:04:35

问题


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()

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


回答1:


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



回答2:


Take a look at the server logs on your web server. In general, error data will be safe on the server. It's not a good idea to dump error logs to users.




回答3:


I think there is something wrong with the ycool.com server, because I couldn't open this url with my web browser.

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

That web server will always return status code 500 Internal Server Error for some url, which should be 200 OK.

If the urlopen function only check for the status code, it will return that error(Although the server send that page's content).



来源:https://stackoverflow.com/questions/8404938/i-get-http-500-error-when-use-python-urllib2-open

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!