English 中文(简体)
圆环2倍于外围,但近距离
原标题:urllib2 times out but doesn t close socket connection

I m 制作一部关于URL gr方案。 为了我的目的,我希望它能够真正迅速地拿出时间,这样我就这样做了。

urllib2.urlopen(, out=2>

当然,这有时是正确的。 但是,它没有双向关闭服务器的连接,因此服务器认为客户仍然有关系。 我怎么能够要求红利2在断裂后关闭联系?

如果我能提供帮助,我就不使用httplib。

我最接近的是:第一次尝试将会结束。 服务器报告说,由于第二次尝试,链接关闭了just<>em>。 然后,服务器报告说,连接线关闭了just<>em>,因为第3次试运行。 定论。

许多感谢。

最佳回答

我怀疑,这张袖珍书仍然开放。 当沙尔提出例外时,它储存着 so框架,这样一刀切,而其他工具则能够看到ack和spe的价值观。

由于历史原因,现在由于落后的相容性, st信息(按渗透方式)储存在玩具中(见 sys.exc_info()、 sys.exc_type和其他)。 这是在3月3日被拆除的一件事。

这对你来说意味着什么,现在还活着。 有一些职能的地方数据是公开的。 因此,该表尚未结束。 只有在拆除了脚石时,所有东西才会被 g。

如果情况如此,就添加类似内容。

try:
  1/0
except ZeroDivisionError:
  pass

页: 1 这为将目前的例外情形换成其他办法提供了快捷的途径。

问题回答

这是一种黑板,但以下的法典奏效。 如果请求具有另一项职能,而且没有引起例外,则总会停止。

def _fetch(self, url):
    try:
        return urllib2.urlopen(urllib2.Request(url), timeout=5).read()
    except urllib2.URLError, e:
        if isinstance(e.reason, socket.timeout):
            return None
        else:
            raise e

def fetch(self, url):
    x = None
    while x is None:
        x = self._fetch(url)
        print "Timeout"
    return x

纽约市是否有更好的办法?





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...