English 中文(简体)
C. 待审案件
原标题:Catch socket timeout exception

我愿随函附上(最好是例外)......。 能够赶上它,但我需要区分死亡链和停尸......。 如果我引用<条码>,但括号除外。 排出时间不能赶上,打字机可停下来。 时间差错

import urllib.request,urllib.parse,urllib.error
import socket
import http
socket.setdefaulttimeout(0.1)


try:
    file2 = urllib.request.Request( http://uk.geforce.com/html:// )
    file2.add_header("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.29 Safari/525.13")
    file3 = urllib.request.urlopen(file2).read().decode("utf8",  ignore )
except urllib.error.URLError: print( fail )
except socket.error: print( fail )
except socket.timeout: print( fail )
except UnicodeEncodeError: print( fail )
except http.client.BadStatusLine: print( fail )
except http.client.IncompleteRead: print( fail )
except urllib.error.HTTPError: print( fail )

print( done )
最佳回答
...
except urllib.error.URLError, e:
    print type(e.reason)

页: 1 时间范围与范围;,只要有预估时间。 这是你们想要的吗?

例如:

try:
  data = urllib2.urlopen("http://www.abcnonexistingurlxyz.com")
except Exception,e:
  print type(e.reason)
... 
<class  socket.timeout >
问题回答

暂无回答




相关问题
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 ]="...

热门标签