python 代码中的奇怪异常 - 机械化和 beautifulsoup

Weird Exception in python code - mechanize and beautifulsoup

I have been getting that weird error in in my application. This is not being generated due to mechanize library because i have put a try-except around it for class Exception.

Plus the browser.open() returns the required address without any issue. Also this exception doesn't come 1 out of 10 times.

I have no idea what it is...

please help

This is the code:

def check_result(self, submission_id, question_code):
    """
    returns the result of a 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 get more specific exception for 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
    for row in rows:
        cells = row.findChildren('td')
        for cell in cells:
            if cell.string == submission_id:
                flag = True
                result = cell.string
                break
        if flag:
            break
    print result

The exact stack trace is :

Exception mechanize._response.httperror_seek_wrapper: 
<httperror_seek_wrapper (urllib2.HTTPError instance) at 0x7fd87195fbb0 
whose wrapped object = <closeable_response at 0x7fd87490dc20 whose fp = 
<response_seek_wrapper at 0x7fd87195c830 whose wrapped object = 
<closeable_response at 0x7fd87195c2d8 whose fp = <socket._fileobject 
object at 0x7fd8719706d0>>>>> in <bound method API.__del__ of 
<CodeChef.API instance at 0x7fd8749249e0>> ignored

Thank you!

and sorry if its an obvious and direct problem.

编辑: Apparently the issue is not with this piece of code, I am still trying to solve it. If you can give any clues that would be really helpful.

The link to the code is : https://github.com/ParadoxZero/CodechefAPI

please comment if I should directly post the code here.

Thank you!

edit 2:

Found the reason for the error, but still don't understand why it happened. I was calling the logout() function in __ del __() removing __ del __() rectified the error.

But still don't understand what it was or why it happened.

找到解决方案,该错误是由于未处理的析构函数中发生的简单异常引起的。

只需编写代码来处理异常或重新抛出异常