Weird Exception in python code - mechanize and beautifulsoup -


i have been getting weird error in in application. not being generated due mechanize library because have put try-except around class exception.

plus browser.open() returns required address without issue. exception doesn't come 1 out of 10 times.

i have no idea is...

please help

this code:

def check_result(self, submission_id, question_code):     """     returns result of problem submission.     :return: result codde     ra - right answer     wa - wrong answer     ce - compilation error     re - runtime error     """     print "================================"     print "response:"     try:         response = self._br.open(self.url + '/status/' + question_code)     except exception: # todo more specific exception better stack trace         raise exceptionset.internetconnectionfailedexception     # print response.read()     response = beautifulsoup(response.read(), 'html.parser')     tables = response.findchildren('table')     table = tables[0]     rows = table.findchildren(['tr', 'th'])     result = ''     flag = false     row in rows:         cells = row.findchildren('td')         cell in cells:             if cell.string == submission_id:                 flag = true                 result = cell.string                 break         if flag:             break     print result 

the exact stack trace :

exception mechanize._response.httperror_seek_wrapper:  <httperror_seek_wrapper (urllib2.httperror instance) @ 0x7fd87195fbb0  wrapped object = <closeable_response @ 0x7fd87490dc20 fp =  <response_seek_wrapper @ 0x7fd87195c830 wrapped object =  <closeable_response @ 0x7fd87195c2d8 fp = <socket._fileobject  object @ 0x7fd8719706d0>>>>> in <bound method api.__del__ of  <codechef.api instance @ 0x7fd8749249e0>> ignored 

thank you!

and sorry if obvious , direct problem.

edit: apparently issue not piece of code, still trying solve it. if can give clues helpful.

the link code : https://github.com/paradoxzero/codechefapi

please comment if should directly post code here.

thank you!

edit 2:

found reason error, still don't understand why happened. calling logout() function in __ del __() removing __ del __() rectified error.

but still don't understand or why happened.

found solution, error occurring due simple exception happening in destructor went unhandled.

simply write code either handle exception or re throw it


Comments