这是我的代码,我已经按照Python文档中的方式处理了异常。但有时候,我不知道发生了什么,我的代码会在
print "SERVER RESPONSE"
这一行卡住,不再继续执行。它甚至不会抛出任何异常。只是在终端上打印出try:
块中的print "SERVER RESPONSE"
后就停止了。def upload(filename1,sampleFile,unknown_path,predictiona,predictionb):
curr_time = (time.strftime("%H:%M:%S"))
curr_day = (time.strftime("%Y-%m-%d"))
register_openers()
datagen, headers = multipart_encode({"sampleFile": open(sampleFile), "name": filename1, "userID":'19','date': curr_day,'time': curr_time})
print"header",headers
request = urllib2.Request("http://videoupload.hopto.org:5000/api/Sync_log", datagen, headers)
try:
print "SERVER RESPONSE"
response = urllib2.urlopen(request)
html=response.read()
except URLError , e:
if hasattr(e, 'reason'):
print 'We failed to reach a server.'
print 'Reason: ', e.reason
elif hasattr(e, 'code'):
print 'The server couldn\'t fulfill the request.'
print 'Error code: ', e.code
else:
print "response ",response
print "html ",html