运行时错误:超过最大递归深度

2024-04-26 13:07:09 发布

您现在位置:Python中文网/ 问答频道 /正文

下面的代码通过匹配不同的模式从文本中提取两个字符串

 def urlChange(self, event):
  text = self.txtUrl.GetValue()
  matches = re.findall('GET (\S+).*Host: (\S+).*Cookie: (.+\S)\s*', text, re.DOTALL or re.MULTILINE)
  if matches:
   groups = matches[0]
   self.txtUrl.SetValue(groups[1] + groups[0])
   self.txtCookie.SetValue(groups[2])
  else:
   matches = re.findall('GET (\S+).*Host: (\S+).*', text, re.DOTALL or re.MULTILINE)
   if matches:
    groups = matches[0]
    self.txtUrl.SetValue(groups[1] + groups[0])
    self.txtCookie.Clear()
   else:
    matches = re.findall('.*(http://\S+)', text, re.DOTALL or re.MULTILINE)
    if matches:
     self.txtUrl.SetValue(matches[0]) 
     matches = re.findall('.*Cookie: (.+\S)', text, re.DOTALL or re.MULTILINE)
     if matches:
      self.txtCookie.SetValue(matches[0])

只有当最后一条re.findall('.*(http://\S+)'...语句运行时,我才会收到以下错误消息:

 Traceback (most recent call last):
   File "./curl-gui.py", line 105, in urlChange
  text = self.txtUrl.GetValue()
 RuntimeError: maximum recursion depth exceeded
 Error in sys.excepthook:
 Traceback (most recent call last):
   File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 48, in apport_excepthook
  if not enabled():
   File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 21, in enabled
  import re
 RuntimeError: maximum recursion depth exceeded while calling a Python object

 Original exception was:
 Traceback (most recent call last):
   File "./curl-gui.py", line 105, in urlChange
  text = self.txtUrl.GetValue()
 RuntimeError: maximum recursion depth exceeded

Tags: ortextinpyselfreiffile