0

很抱歉,这可能是一个基本问题,但是当我学习scrubadub 并试图让它自己在Jupyter notebook 上工作时。它一直显示 - HTTP Error 503: Service Unavailable 这是我输入的内容,与scrubadub文档完全相同。

text = u"John is a cat"
scrubadub.clean(text, replace_with='placeholder') 
u"{{NAME}} is a cat"

这是我收到的错误消息:

HTTPError                                 Traceback (most recent call last)
<ipython-input-92-5b0754baae94> in <module>()
      1 text = u"John is a cat"
----> 2 scrubadub.clean(text, replace_with='placeholder')
      3 u"{{NAME}} is a cat"

/anaconda3/lib/python3.7/site-packages/scrubadub/__init__.py in clean(text, cls, **kwargs)
     14     cls = cls or Scrubber
     15     scrubber = cls()
---> 16     return scrubber.clean(text, **kwargs)

/anaconda3/lib/python3.7/site-packages/scrubadub/scrubbers.py in clean(self, text, **kwargs)
     55         clean_chunks = []
     56         filth = Filth()
---> 57         for next_filth in self.iter_filth(text):
     58             clean_chunks.append(text[filth.end:next_filth.beg])
     59             clean_chunks.append(next_filth.replace_with(**kwargs))

错误截图#1 错误截图#2

我也在这里尝试了下面的代码,我也收到了错误消息,我猜我是否遗漏了代码中的任何参数......

import scrubadub
class MyFilth(scrubadub.filth.base.Filth):
    type = 'mine'
class MyDetector(scrubadub.detectors.base.Detector):
    filth_cls = MyFilth
    def iter_filth(self, text):
       # do something here
       pass

scrubber = scrubadub.Scrubber()
scrubber.add_detector(MyDetector)

text = u"My stuff can be found there"
scrubadub.clean(text)
u"{{MINE}} can be found there."

StopIteration                             Traceback (most recent call last)
/anaconda3/lib/python3.7/site-packages/scrubadub/detectors/base.py in iter_filth(self, text)
     21         if self.filth_cls.regex is None:
---> 22             raise StopIteration
     23         for match in self.filth_cls.regex.finditer(text):

StopIteration: 

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
<ipython-input-94-2cc23d003da7> in <module>()
     11 
     12 text = u"My stuff can be found there"
---> 13 scrubadub.clean(text)
     14 u"{{MINE}} can be found there."

/anaconda3/lib/python3.7/site-packages/scrubadub/__init__.py in clean(text, cls, **kwargs)
     14     cls = cls or Scrubber
     15     scrubber = cls()
---> 16     return scrubber.clean(text, **kwargs)
4

1 回答 1

1

在 github 上存在一个未解决的问题,因为 scrubadub 似乎不适用于您当前使用的 python 3.7。

我也能够在没有笔记本的情况下用 3.7 重现它。所以肯定是笔记本的问题。

作为一个临时解决方案,将您的环境更改为 3.6(或最不推荐的最坏情况 2.7)是可行的。

https://github.com/datascopeanalytics/scrubadub/issues/40停止迭代问题

于 2019-03-21T05:49:14.317 回答