Exception while calling 'pip.main(...)' from a Flask-Restful application
See original GitHub issue- Pip version: 9.0.1
- Python version: 2.7.10
- Operating system: Macos (Darwin Kernel Version 16.5.0)
Description:
I’m running an application using Flask-Restful (0.3.5), which exposes several APIs. I’m trying to uninstall a module using pip.main(['uninstall', '-y', '--log', 'pip.log','foobar'])
. This function returns 2
, and the following exception is logged
Uninstalling foobar:
Exception:
Traceback (most recent call last):
File "/Users/jmdacruz/workspace/App/build/virtualenv/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Users/jmdacruz/workspace/App/build/virtualenv/lib/python2.7/site-packages/pip/commands/uninstall.py", line 76, in run
requirement_set.uninstall(auto_confirm=options.yes)
File "/Users/jmdacruz/workspace/App/build/virtualenv/lib/python2.7/site-packages/pip/req/req_set.py", line 346, in uninstall
req.uninstall(auto_confirm=auto_confirm)
File "/Users/jmdacruz/workspace/App/build/virtualenv/lib/python2.7/site-packages/pip/req/req_install.py", line 754, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Users/jmdacruz/workspace/App/build/virtualenv/lib/python2.7/site-packages/pip/req/req_uninstall.py", line 95, in remove
with indent_log():
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/Users/jmdacruz/workspace/App/build/virtualenv/lib/python2.7/site-packages/pip/utils/logging.py", line 34, in indent_log
_log_state.indentation += num
AttributeError: 'thread._local' object has no attribute 'indentation'
What I’ve run:
pip.main(['uninstall', '-y', 'foobar'])
pip.main(['uninstall', '-y', '--log', 'pip.log','foobar'])
...
The command above returns 2
(which I think is UNKNOWN
). I also tried replacing pip’s logger in memory instead of using the --log
parameter to pip.main(...)
, but the result was the same. It seems that this could be solved with a failsafe here and here when the attribute indentation
is not set on _log_state
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How To Handle Errors in a Flask Application - DigitalOcean
You will see the following response: Not Found The requested URL was not found on the server.
Read more >Why is my Flask error handler not being called? - Stack Overflow
It appears that MyGenericException is being raised properly, but Flask seems to ignore it. The @app.
Read more >Handling Application Errors — Flask Documentation (2.2.x)
When Flask catches an exception while handling a request, it is first looked up by code. If no handler is registered for the...
Read more >API Docs — Flask-RESTful 0.3.8 documentation
A decorator that apply marshalling to the return values of your methods. A decorator that formats the return values of your methods with...
Read more >Why and how to handle exceptions in Python Flask
What do you want to do if the app fails to communicate with Threat Stack? You're going to raise a new exception. This...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Using pip’s internal functions from within another application is not supported, sorry. I suggest trying to run pip in a subprocess.
But please note that the behaviour of a running Python program if a module it’s using is uninstalled is not well defined. It’s quite possible that even if you run pip in a subprocess, your application may not behave as expected after the uninstall.
Yup 🙂