question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

does not work with python 3.7.1 raises StopIteration

See original GitHub issue

i am trying to run the example with python 3.7.1 but it raises a generator StopIteration

example:

s = u"John is a cat"
t = scrubadub.clean(s)

output

Traceback (most recent call last):
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/textblob/_text.py", line 365, in _read
    raise StopIteration
StopIteration

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

Traceback (most recent call last):
  File "test.py", line 20, in <module>
    t = scrubadub.clean(s)
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/scrubadub/__init__.py", line 16, in clean
    return scrubber.clean(text, **kwargs)
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/scrubadub/scrubbers.py", line 57, in clean
    for next_filth in self.iter_filth(text):
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/scrubadub/scrubbers.py", line 76, in iter_filth
    for filth in detector.iter_filth(text):
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/scrubadub/detectors/name.py", line 29, in iter_filth
    for word, part_of_speech in blob.tags:
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/textblob/decorators.py", line 24, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/textblob/blob.py", line 447, in pos_tags
    for word, t in self.pos_tagger.tag(self.raw)
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/textblob/en/taggers.py", line 21, in tag
    return pattern_tag(text, tokenize)
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/textblob/en/__init__.py", line 115, in tag
    for sentence in parse(s, tokenize, True, False, False, False, encoding).split():
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/textblob/en/__init__.py", line 99, in parse
    return parser.parse(unicode(s), *args, **kwargs)
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/textblob/_text.py", line 1240, in parse
    s[i] = self.find_tags(s[i], **kwargs)
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/textblob/en/__init__.py", line 49, in find_tags
    return _Parser.find_tags(self, tokens, **kwargs)
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/textblob/_text.py", line 1188, in find_tags
    map = kwargs.get(     "map", None))
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/textblob/_text.py", line 978, in find_tags
    tagged.append([token, lexicon.get(token, i == 0 and lexicon.get(token.lower()) or None)])
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/textblob/_text.py", line 104, in get
    return self._lazy("get", *args)
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/textblob/_text.py", line 85, in _lazy
    self.load()
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/textblob/_text.py", line 382, in load
    dict.update(self, (x.split(" ")[:2] for x in _read(self._path) if x.strip()))
  File "/Users/nihil/.pyenv/versions/emailbin/lib/python3.7/site-packages/textblob/_text.py", line 382, in <genexpr>
    dict.update(self, (x.split(" ")[:2] for x in _read(self._path) if x.strip()))
RuntimeError: generator raised StopIteration

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:12
  • Comments:8

github_iconTop GitHub Comments

3reactions
apdamecommented, Oct 24, 2019

I appear to be having the same issue in Python 3.8.0, with all dependencies updated to the latest version:

Traceback (most recent call last):
  File "C:\Python3\lib\site-packages\scrubadub\detectors\base.py", line 22, in iter_filth
    raise StopIteration
StopIteration

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

Traceback (most recent call last):
  File "threadparser.py", line 116, in <module>
    main()
  File "threadparser.py", line 95, in main
    parser()
  File "threadparser.py", line 85, in parser
    redact(jsonMsg, jsonStr, mid)
  File "threadparser.py", line 35, in redact
    msg = scrubadub.clean(msgUnescape, replace_with='identifier')
  File "C:\Python3\lib\site-packages\scrubadub\__init__.py", line 16, in clean
    return scrubber.clean(text, **kwargs)
  File "C:\Python3\lib\site-packages\scrubadub\scrubbers.py", line 57, in clean
    for next_filth in self.iter_filth(text):
  File "C:\Python3\lib\site-packages\scrubadub\scrubbers.py", line 76, in iter_filth
    for filth in detector.iter_filth(text):
RuntimeError: generator raised StopIteration

Not sure what’s raising the error so early on, unless there’s something obvious I’m missing or a formatting issue.

0reactions
parthpanchal3399commented, Apr 8, 2020

cc: @deanmalmgren

textblob 0.15.2 seems to fix this StopIteration error, but the upgrade brings along some other errors.

  File "test.py", line 3, in <module>
    print(scrubadub.clean("John spoke with Doug.", replace_with='identifier'))
  File "/Users/noqcks/.local/share/virtualenvs/api-MnT524yV/lib/python3.7/site-packages/scrubadub/__init__.py", line 16, in clean
    return scrubber.clean(text, **kwargs)
  File "/Users/noqcks/.local/share/virtualenvs/api-MnT524yV/lib/python3.7/site-packages/scrubadub/scrubbers.py", line 57, in clean
    for next_filth in self.iter_filth(text):
  File "/Users/noqcks/.local/share/virtualenvs/api-MnT524yV/lib/python3.7/site-packages/scrubadub/scrubbers.py", line 76, in iter_filth
    for filth in detector.iter_filth(text):
  File "/Users/noqcks/.local/share/virtualenvs/api-MnT524yV/lib/python3.7/site-packages/scrubadub/detectors/name.py", line 40, in iter_filth
    re_list.append(r'\b' + re.escape(proper_noun) + r'\b')
  File "/Users/noqcks/.local/share/virtualenvs/api-MnT524yV/lib/python3.7/re.py", line 257, in escape
    return pattern.translate(_special_chars_map)
  File "/Users/noqcks/.local/share/virtualenvs/api-MnT524yV/lib/python3.7/site-packages/textblob/blob.py", line 101, in translate
    from_lang=from_lang, to_lang=to)
  File "/Users/noqcks/.local/share/virtualenvs/api-MnT524yV/lib/python3.7/site-packages/textblob/translate.py", line 54, in translate
    response = self._request(url, host=host, type_=type_, data=data)
  File "/Users/noqcks/.local/share/virtualenvs/api-MnT524yV/lib/python3.7/site-packages/textblob/translate.py", line 92, in _request
    resp = request.urlopen(req)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 543, in _open
    '_open', req)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1345, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1317, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1244, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1255, in _send_request
    self.putrequest(method, url, **skips)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1117, in putrequest
    raise InvalidURL(f"URL can't contain control characters. {url!r} "
http.client.InvalidURL: URL can't contain control characters. "/translate_a/t?client=webapp&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=2&ssel=0&tsel=0&kc=1&sl={40: '\\\\(', 41: '\\\\)', 91: '\\\\[', 93: '\\\\]', 123: '\\\\{', 125: '\\\\}', 63: '\\\\?', 42: '\\\\*', 43: '\\\\+', 45: '\\\\-', 124: '\\\\|', 94: '\\\\^', 36: '\\\\$', 92: '\\\\\\\\', 46: '\\\\.', 38: '\\\\&', 126: '\\\\~', 35: '\\\\" (found at least ' ')```

Hey. I am having the same error for python 3.8.2 Any fixes?

Read more comments on GitHub >

github_iconTop Results From Across the Web

does not work with python 3.7.1 raises StopIteration · Issue #40
i am trying to run the example with python 3.7.1 but it raises a generator StopIteration example: s = u"John is a cat"...
Read more >
Python 3.7: StopIteration could be your next headache
Our library implements a tiny wrapper over the official python client library. Right, probably raising a StopIteration instead of simply return ...
Read more >
generator raised StopIteration" every time I try to run app ...
To judge from the file paths, it looks like you're running Python 3.7. ... This won't execute RuntimeError: generator raised StopIteration ...
Read more >
PEP 479 – Change StopIteration handling inside generators
This PEP proposes a change to generators: when StopIteration is raised inside a generator, it is replaced with RuntimeError . (More precisely, this...
Read more >
Iterators - The Conservative Python 3 Porting Guide
Since Python 3.7, generators cannot raise StopIteration directly, but must stop with return (or at the end of the function). This change was...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found