Python - Scrubadub.clean无法正常工作 - 无法正确擦除文本PII + HTTP错误503

问题描述 投票:0回答:1

对不起,这可能是一个基本的问题,但是当我正在学习scrubadub并试图让自己在Jupyter笔记本上工作。它一直显示 - HTTP错误503:服务不可用这是我输入的内容,它与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))

screenshot for error#1 screenshot for error#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)
python package runtime-error http-error stopiteration
1个回答
1
投票

在github上有一个开放的问题,因为scrubadub似乎与你目前使用的python 3.7不太合作。

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

作为临时解决方案,将您的env更改为3.6(或最差情况2.7高度不推荐)有效。

https://github.com/datascopeanalytics/scrubadub/issues/40Stop Iteration issue

© www.soinside.com 2019 - 2024. All rights reserved.