This is my code where i have handled the exceptions the way it is written in python documentation but sometimes i do not know what happens but my code stuck at this print "SERVER RESPONSE"
line and does not continue any forward and I have to forcibly stop it. It does not even throw any exception.It just came to halt after this print "SERVER RESPONSE"
in try:
block is printed on terminal.
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