Python / Django“BadStatusLine”错误 [英] Python/Django "BadStatusLine" error

查看:347
本文介绍了Python / Django“BadStatusLine”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的错误,我似乎找不到解决方案。

I'm getting a weird error that I can't seem to find a solution for.

这个错误不会发生每次我打这段代码,并且它也不会发生在循环中的相同迭代(它发生在循环中)。如果我运行足够,似乎没有遇到错误,程序执行成功。无论如何,我还是想弄清楚为什么会发生这种情况。

This error does not occur every time I hit this segment of code, and neither does it happen for the same iteration through the loop (it happens in a loop). If I run it enough, it doesn't seem to encounter the error and the program executes successfully. Regardless, I'd still like to figure out why this is happening.

这是我的错误,版本,跟踪等: http://dpaste.com/681658/

Here is my error, versions, trace, etc: http://dpaste.com/681658/

似乎在我的代码中出现以下代码:

It seems to happen with the following line in my code:

page = urllib2.urlopen(url)

其中url是....一个URL显然。

Where url is.... a URL obviously.

并且有 import urllib2

推荐答案

BadStatusLine 当您调用 urllib2.urlopen(url)时引发异常),远程服务器使用python不能理解的状态代码进行响应。

The BadStatusLine exception is raised when you call urllib2.urlopen(url) and the remote server responds with a status code that python cannot understand.

假设您不控制 url ,你不能阻止这种情况发生。所有你可以做的是捕获异常,并优雅地管理。

Assuming that you don't control url, you can't prevent this from happening. All you can do is catch the exception, and manage it gracefully.

from httplib import BadStatusLine

try:
    page = urllib2.urlopen(url)
    # do something with page
except BadStatusLine:
    print "could not fetch %s" % url

这篇关于Python / Django“BadStatusLine”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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