I am trying to run this code:
import web
urls = (
'/', 'index'
)
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
But it gives me this error everytime
C:\Users\aidke\Desktop>python app.py
Traceback (most recent call last):
File "C:\Users\aidke\AppData\Local\Programs\Python\Python37-32\lib\site-packages\web\utils.py", line 526, in take
yield next(seq)
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "app.py", line 14, in <module>
app = web.application(urls, globals())
File "C:\Users\aidke\AppData\Local\Programs\Python\Python37-32\lib\site-packages\web\application.py", line 62, in __init__
self.init_mapping(mapping)
File "C:\Users\aidke\AppData\Local\Programs\Python\Python37-32\lib\site-packages\web\application.py", line 130, in init_mapping
self.mapping = list(utils.group(mapping, 2))
File "C:\Users\aidke\AppData\Local\Programs\Python\Python37-32\lib\site-packages\web\utils.py", line 531, in group
x = list(take(seq, size))
RuntimeError: generator raised StopIteration
I tried someone else's code and the exact same thing happened. Additionally I tried reinstalling web.py(experimental) but it still didn't work.
To judge from the file paths, it looks like you're running Python 3.7. If so, you're getting caught by new-in-3.7 behavior:
PEP 479 is enabled for all code in Python 3.7, meaning that StopIteration exceptions raised directly or indirectly in coroutines and generators are transformed into RuntimeError exceptions. (Contributed by Yury Selivanov in bpo-32670.)
Before this change, a StopIteration raised by, or passing through, a generator simply ended the generator's useful life (the exception was silently swallowed). The module you're using will have to be recoded to work as intended with 3.7.
Chances are they'll need to change:
yield next(seq)
to:
try:
yield next(seq)
except StopIteration:
return
So during my recent self-learning on Python, a course required me to install Web.py and I was getting this error and as one of the answer stated, it had to be updated to be compatible with Python 3.7.
I installed the package with pip3 install web.py==0.40-dev1 ran into this error and started searching the web for a solution.
What I did was search through webpy git and find the utils.py file that was more recent in https://github.com/webpy/webpy/tree/master/web, downloaded it, and used it to replace the one that was in my Lib/site-packages/web folder (I'm a Windows user) and it just worked.
Hope this help someone.
My solution was to upgrade these pips
mongoengine from 0.14.0 to 0.19.1
and
flask-mongoengine to 0.9.5
it worked.
Most major packages have fixed this issue by now, but one major package that hasn't is the clips/pattern project. It hasn't been updated since August 2018, so it never received a fix.
Since this is the top Google result for "python pattern stopiteration", here's a workaround:
def pattern_stopiteration_workaround():
try:
print(lexeme('gave'))
except:
pass
def main():
pattern_stopiteration_workaround()
#Add your other code here
Basically, the pattern-related code will only fail the first time you run it, so you first need to run it once and catch the Exception that it throws.
It's worked well enough for my own scripts, but I don't know if it fixes every possible issue.
Ideally though, somebody should fork the clips/pattern project since it's no longer maintained.
They fixed this issue, just uninstall your current web.py version and I got an error when running pip install web.py from windows 10. So I run the pip install -e git+https://github.com/webpy/webpy.git#egg=webpy command to get the latest version from master branch. This won't execute RuntimeError: generator raised StopIteration error as question mentioned.
This should be fixed in #577:
https://github.com/webpy/webpy/pull/577
I was facing the same issue for below command
python setup.py test
Error solved when I upgraded the pytest version
pip uninstall pytest
pip install pytest
Related
I've run into this issue while using the jira library for python. Despite setting the appropriate parameters for basic auth, I get the following:
Exception ignored in: <bound method Magic.del of <magic.Magic object at 0x7f2a4e5ff128>>
Traceback (most recent call last):
File "/home/keckj/.local/lib/python3.6/site-packages/magic.py", line 129, in del
if self.cookie and magic_close:
AttributeError: 'Magic' object has no attribute 'cookie'
Here's a quick snippet:
from jira import JIRA
user = 'xxxx.xxxxx#xxxxxx.com'
apikey = 'xxxxxxxxxxxxxxxxxxxxx'
jira_server = 'https://xxxxxxxxxx.jira.com'
options = {'server': jira_server}
jira = JIRA(options, basic_auth=(user,apikey))
issue = jira.issue("KEY-123")
issue_summary = issue.fields.summary
issue_description = issue.fields.description
print('JIRA ISSUE SUMMARY: %s' %str(issue_summary))
print('JIRA ISSUE DESCRIPTION: %s' %str(issue_description))
I've dug in a few directions via Google but been coming up short:
https://github.com/Linaro/jipdate/issues/30
https://github.com/ahupp/python-magic/issues/47
Python attributeError on __del__
https://github.com/ahupp/python-magic/pull/222
I found the answer buried at bottom of https://github.com/ahupp/python-magic/pull/222:
Apparently python-jira expects the filemagic python package, which takes a flags parameter, but for some reason our environment had your python-magic package, which expects different parameters.
Direct link: https://github.com/ahupp/python-magic/pull/222#issuecomment-675354824
To resolve this, I ran pip install filemagic and voila, no further exceptions.
I tried the "pip install filemagic", but it didn't fix it. It looks like the python-magic module is still installed, and getting picked up. However, another library I use, thehive4py lists python-magic as a dependancy.
You have to also uninstall python-magic at both the system (sudo) and user level. "pip3 uninstall python-magic". But, as stated before, it might/will break other libraries.
Why would someone think it is a good idea to have pip modules with conflicting names? Then, have one throw an error due to poor programing practices. jeesh.
I'm getting an error when I try to run my tool from the command line. I've created a setup.py file and put together the entry point. This command line util works when I clone the repo and install on other computers. I wonder if the issue has something to do with the dev tag thats included in the location of package. ('this_tool==0.1.1.dev11')
By using python setup.py --version it's on 0.1.1.dev16. But I'm not sure how to fix this as rerunning the setup.py install doesn't seem to fix the problem.
Traceback (most recent call last):
File "/Users/USERNAME/miniconda2/envs/USERNAME/bin/this_tool", line 30, in <module>
sys.exit(load_entry_point('this_tool==0.1.1.dev11', 'console_scripts', 'this_tool')())
File "/Users/USERNAME/miniconda2/envs/USERNAME/bin/this_tool", line 22, in importlib_load_entry_point
return next(matches).load()
StopIteration
I can provide my setup.py if needed too, but since it seemed to work on the other computers I don't think that's the problem
In my case this happened when i had two versions of the same package. An older version which didn't have the script and a new version with the console_script installed by setup.py.
The discussion in https://github.com/pypa/setuptools/issues/2390
pointed me in the direction to try out a
pip uninstall mypackage
and i was asked interactively to remove the older version of the package.
After that the StopIteration issue went away.
I had the exact same problem with BorgBackup installed from Entware-ng (opkg) on my NAS
$ /opt/bin/borg
Traceback (most recent call last):
File "/opt/bin/borg", line 33, in <module>
sys.exit(load_entry_point('borgbackup==1.1.16', 'console_scripts', 'borg')())
File "/opt/bin/borg", line 25, in importlib_load_entry_point
return next(matches).load()
StopIteration
and as #anup-jonchhe commented above, a fresh install indeed solved the problem.
But I could also fix this issue without a full reinstallation.
In my setup, the problem occurred right after an update of the tool
opkg update && opkg upgrade python3-borgbackup
The problem is that the upgrade process left some conflicting directory which raised the error
In the directory /opt/lib/python3.9/site-packages
the upgrade from BorgBackup 1.1.15-1 to 1.1.16-1 left the old directory
borgbackup-1.1.15-py3.9.egg-info/
next to the new one
borgbackup-1.1.16-py3.9.egg-info/
After removing manually the old one (1.1.15), borg would run again without any problem
I am trying to run this code:
import web
urls = (
'/', 'index'
)
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
But it gives me this error everytime
C:\Users\aidke\Desktop>python app.py
Traceback (most recent call last):
File "C:\Users\aidke\AppData\Local\Programs\Python\Python37-32\lib\site-packages\web\utils.py", line 526, in take
yield next(seq)
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "app.py", line 14, in <module>
app = web.application(urls, globals())
File "C:\Users\aidke\AppData\Local\Programs\Python\Python37-32\lib\site-packages\web\application.py", line 62, in __init__
self.init_mapping(mapping)
File "C:\Users\aidke\AppData\Local\Programs\Python\Python37-32\lib\site-packages\web\application.py", line 130, in init_mapping
self.mapping = list(utils.group(mapping, 2))
File "C:\Users\aidke\AppData\Local\Programs\Python\Python37-32\lib\site-packages\web\utils.py", line 531, in group
x = list(take(seq, size))
RuntimeError: generator raised StopIteration
I tried someone else's code and the exact same thing happened. Additionally I tried reinstalling web.py(experimental) but it still didn't work.
To judge from the file paths, it looks like you're running Python 3.7. If so, you're getting caught by new-in-3.7 behavior:
PEP 479 is enabled for all code in Python 3.7, meaning that StopIteration exceptions raised directly or indirectly in coroutines and generators are transformed into RuntimeError exceptions. (Contributed by Yury Selivanov in bpo-32670.)
Before this change, a StopIteration raised by, or passing through, a generator simply ended the generator's useful life (the exception was silently swallowed). The module you're using will have to be recoded to work as intended with 3.7.
Chances are they'll need to change:
yield next(seq)
to:
try:
yield next(seq)
except StopIteration:
return
So during my recent self-learning on Python, a course required me to install Web.py and I was getting this error and as one of the answer stated, it had to be updated to be compatible with Python 3.7.
I installed the package with pip3 install web.py==0.40-dev1 ran into this error and started searching the web for a solution.
What I did was search through webpy git and find the utils.py file that was more recent in https://github.com/webpy/webpy/tree/master/web, downloaded it, and used it to replace the one that was in my Lib/site-packages/web folder (I'm a Windows user) and it just worked.
Hope this help someone.
My solution was to upgrade these pips
mongoengine from 0.14.0 to 0.19.1
and
flask-mongoengine to 0.9.5
it worked.
Most major packages have fixed this issue by now, but one major package that hasn't is the clips/pattern project. It hasn't been updated since August 2018, so it never received a fix.
Since this is the top Google result for "python pattern stopiteration", here's a workaround:
def pattern_stopiteration_workaround():
try:
print(lexeme('gave'))
except:
pass
def main():
pattern_stopiteration_workaround()
#Add your other code here
Basically, the pattern-related code will only fail the first time you run it, so you first need to run it once and catch the Exception that it throws.
It's worked well enough for my own scripts, but I don't know if it fixes every possible issue.
Ideally though, somebody should fork the clips/pattern project since it's no longer maintained.
They fixed this issue, just uninstall your current web.py version and I got an error when running pip install web.py from windows 10. So I run the pip install -e git+https://github.com/webpy/webpy.git#egg=webpy command to get the latest version from master branch. This won't execute RuntimeError: generator raised StopIteration error as question mentioned.
This should be fixed in #577:
https://github.com/webpy/webpy/pull/577
I was facing the same issue for below command
python setup.py test
Error solved when I upgraded the pytest version
pip uninstall pytest
pip install pytest
I was about to set up pygobject for gtk+3. This http://python-gtk-3-tutorial.readthedocs.org/en/latest/install.html#id2 page says I need Jhbuild. I went ahead and installed that. But, it gives me traceback
Traceback (most recent call last):
File "/usr/bin/jhbuild", line 6, in <module>
import __builtin__
ImportError: No module named '__builtin__'
Which obviously is due to wrong version of python(my default is python3).
So, I found this page https://wiki.gnome.org/Projects/Jhbuild/Dependencies/ArchLinux
Which suggests to add
os.environ['PYTHON'] = '/usr/bin/python2'
line to ~/.config/jhbuildrc which I did. When I run jhbuild again it spews the same traceback.
I tried putting the file as ~/.jhbuildrc. Doesn't work either.
So, I'm stuck here. Any help would be appreciated.
I'm on Arch Linux, fwiw.
You probably want to set PYTHON=/usr/bin/python2 when you ./autogen.sh --simple-install for jhbuild itself. The jhbuildrc file is only used for things it builds.
See also: https://wiki.archlinux.org/index.php/JHBuild
I found a code which i need. It is from this link : How to install a package using the python-apt API
#!/usr/bin/env python
# aptinstall.py
import apt
import sys
pkg_name = "libjs-yui-doc"
cache = apt.cache.Cache()
cache.update() # error is in this line
pkg = cache[pkg_name]
if pkg.is_installed:
print "{pkg_name} already installed".format(pkg_name=pkg_name)
else:
pkg.mark_install()
try:
cache.commit()
except Exception, arg:
print >> sys.stderr, "Sorry, package installation failed [{err}]".format(err=str(arg))
However i can't make it work. I searched about the problem on the web. It is said that there should be no package manager,apt,pip etc active in order to work with this code. However, no package manager,apt,pip etc. is open in my computer. I thought that when computer starts, some package manager can be active. So i typed
ps -aux
in terminal and look at the active processes, but i didn't see any active process related to package manager(i'm not %100 sure about this, because any process i don't know can be related to package manager.But how could i know it?) To sum up,i started the computer and opened only terminal. Then i typed python aptinstall.py and hit enter. I take the following error :
Traceback (most recent call last):
File "aptinstall.py", line 7, in <module>
cache.update()
File "/usr/lib/python2.7/dist-packages/apt/cache.py", line 397, in update
raise LockFailedException("Failed to lock %s" % lockfile)
apt.cache.LockFailedException: Failed to lock /var/lib/apt/lists/lock
I delete the lock by giving the command in terminal :
sudo rm /var/lib/dpkg/lock
It didn't work too.
How can i solve this problem? Any idea will be appreciated.
Please try looking for update-manager in ps. It runs automatically on a periodic basis, so it may be locking the apt db.
There are three different reasons which cause this error.
1 - As i mentioned earlier, if any package manager is runnning(for example;pip,apt-get,synaptic,etc), it gives the error.
2 - If you are using your ubuntu in a virtual machine, this causes the same error.
3 - If you are running your program without root privileges, this causes the same error. For example ,if you are running your program with "python aptinstall.py" you get the error, running the program with "sudo python aptinstall.py" is the correct one.