gpt4 book ai didi

python-2.7 - python 代码中的奇怪异常 - mechanize 和 beautifulsoup

转载 作者:行者123 更新时间:2023-12-04 16:18:36 24 4
gpt4 key购买 nike

我在我的应用程序中遇到了那个奇怪的错误。
由于 Mechanize 库,这不是生成的,因为我已经为异常类在它周围放置了一个 try-except 。

另外, browser.open() 返回所需的地址,没有任何问题。
此外,此异常不会出现 10 次中的 1 次。

我不知道它是什么...

请帮忙

这是代码:

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

确切的堆栈跟踪是:
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

谢谢!

如果这是一个明显而直接的问题,我很抱歉。

编辑:
显然问题不在于这段代码,
我仍在努力解决它。如果你能提供任何线索,那将是非常有帮助的。

代码的链接是:
https://github.com/ParadoxZero/CodechefAPI

如果我应该在这里直接发布代码,请发表评论。

谢谢!

编辑2:

找到了错误的原因,但仍然不明白为什么会发生。我在 __ del __() 中调用 logout() 函数
删除 __ del __() 纠正了错误。

但仍然不明白它是什么或为什么会发生。

最佳答案

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

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

关于python-2.7 - python 代码中的奇怪异常 - mechanize 和 beautifulsoup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38833878/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com