jzempel / flask-exceptional Goto Github PK
View Code? Open in Web Editor NEWExceptional extension for Flask
Home Page: http://packages.python.org/Flask-Exceptional
License: Other
Exceptional extension for Flask
Home Page: http://packages.python.org/Flask-Exceptional
License: Other
Would be nice to be able to access the Exceptional object via app.extensions. The flask-babel extension for instance does this:
ipdb> pp app.extensions
{'babel': <flaskext.babel.Babel object at 0x102a51b10>,
'exceptional': {'name': 'flask-exceptional',
'protocol_version': 5,
'version': 'unknown'}}
Is this a standard practice, or is there some other place it's kicking around?
I'd like to use flask-exceptional in my Flask app, but I'm on App Engine which is unfortunately still Python 2.5. Any interest in using something like https://github.com/florentx/stringformat so flask-exceptional won't break on Python 2.5?
I'm trying to integrate flask-exceptional into our rq job queue. This seemed straightforward since you have provided Exceptional.publish but I've ran into a few issues. I'm not sure if this is user error or an actual regression. It appears that the flask-extension code is still expecting the request context when it shouldn't.
Here is my error handler code for rq:
def report_to_exceptional_handler(job, exc_type, exc_value, traceback):
tb = Traceback(exc_type, exc_value, traceback)
Exceptional.publish(gotham.app.config, tb)
I then get the following exception.
[2013-02-07 21:16] DEBUG: horse: Invoking exception handler <function report_to_exceptional_handler at 0xb7e52a8>
Traceback (most recent call last):
File "worker.py", line 31, in <module>
w.work()
File "/home/bryan/.virtualenvs/gotham/local/lib/python2.7/site-packages/rq/worker.py", line 326, in work
self.fork_and_perform_job(job)
File "/home/bryan/.virtualenvs/gotham/local/lib/python2.7/site-packages/rq/worker.py", line 342, in fork_and_perform_job
self.main_work_horse(job)
File "/home/bryan/.virtualenvs/gotham/local/lib/python2.7/site-packages/rq/worker.py", line 377, in main_work_horse
success = self.perform_job(job)
File "/home/bryan/.virtualenvs/gotham/local/lib/python2.7/site-packages/rq/worker.py", line 402, in perform_job
self.handle_exception(job, *sys.exc_info())
File "/home/bryan/.virtualenvs/gotham/local/lib/python2.7/site-packages/rq/worker.py", line 443, in handle_exception
fallthrough = handler(job, *exc_info)
File "worker.py", line 16, in report_to_exceptional_handler
Exceptional.publish(gotham.app.config, tb)
File "/home/bryan/.virtualenvs/gotham/local/lib/python2.7/site-packages/flask_exceptional.py", line 144, in publish
exceptional._post_data(traceback=traceback)
File "/home/bryan/.virtualenvs/gotham/local/lib/python2.7/site-packages/flask_exceptional.py", line 232, in _post_data
app = context.app if context else stack.top.app
AttributeError: 'NoneType' object has no attribute 'app'
It appears that this code is trying to pull out the variable stack.app.top where stack is really a flask._request_ctx_stack. However when I'm in my job queue we do not have a request context which is exactly what I thought the publish function was built to handle. Am I just using this incorrectly or should I submit a patch?
Thanks.
-bryan
Thanks.
Flask-exceptional is throwing the following error whenever it tries to post an exception:
Traceback (most recent call last):
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 174, in Handle
result = handler(self._environ, self._StartResponse)
File "packages/flask/app.py", line 1518, in __call__
return self.wsgi_app(environ, start_response)
File "packages/flask/app.py", line 1506, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "packages/flaskext/exceptional.py", line 142, in ret_val
self._post_data(context)
File "packages/flaskext/exceptional.py", line 184, in _post_data
"exception": self.__get_exception_data(traceback)
File "/base/python27_runtime/python27_dist/lib/python2.7/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/base/python27_runtime/python27_dist/lib/python2.7/json/encoder.py", line 201, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/base/python27_runtime/python27_dist/lib/python2.7/json/encoder.py", line 264, in iterencode
return _iterencode(o, 0)
File "/base/python27_runtime/python27_dist/lib/python2.7/json/encoder.py", line 178, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <cStringIO.StringI object at 0x2981158> is not JSON serializable
I am using the new python27 App Engine runtime.
I am trying to use Flask-Exceptional on Mac OSX version 10.9.3 on python 2.7.5 .
On calling Exceptional(app)
an error is encountered.
Here's the traceback.
Traceback (most recent call last):
File "__init__.py", line 1, in <module>
from app import app, login_manager, redis_client, api
File "/Users/tushar/dev/frankly/api/app.py", line 14, in <module>
exceptional = Exceptional(app)
File "/Library/Python/2.7/site-packages/flask_exceptional.py", line 53, in __init__
self.init_app(app)
File "/Library/Python/2.7/site-packages/flask_exceptional.py", line 100, in init_app
app.handle_exception = self._get_exception_handler(app)
File "/Library/Python/2.7/site-packages/flask_exceptional.py", line 198, in _get_exception_handler
@wraps(handle_exception)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 33, in update_wrapper
setattr(wrapper, attr, getattr(wrapped, attr))
AttributeError: 'functools.partial' object has no attribute '__module__'
Here's what i found on stackoverflow.
Error encountered using decorator to update wrapper
Please Look into the problem.
Thanks.
_post_data doesn't catch URLError or HTTPError exceptions. Patch forthcoming.
Flask-Exceptional dies when setting cookie values in 2.6.4:
Traceback (most recent call last):
File "/var/home/steven-kryskalla/project/lib/python2.6/site-packages/Flask-0.7dev_20110406-py2.6.egg/flask/app.py", line 1014, in __call__
return self.wsgi_app(environ, start_response)
File "/var/home/steven-kryskalla/project/lib/python2.6/site-packages/Flask-0.7dev_20110406-py2.6.egg/flask/app.py", line 1002, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/var/home/steven-kryskalla/project/lib/python2.6/site-packages/flaskext/exceptional.py", line 144, in ret_val
self._post_data(context)
File "/var/home/steven-kryskalla/project/lib/python2.6/site-packages/flaskext/exceptional.py", line 180, in _post_data
"request": self.__get_request_data(context.app, context.request, context.session),
File "/var/home/steven-kryskalla/project/lib/python2.6/site-packages/flaskext/exceptional.py", line 294, in __get_request_data
headers["Cookie"] = cookie.output(header='', sep=';').strip()
File "/var/home/steven-kryskalla/Python-2.6.4/Lib/Cookie.py", line 594, in output
result.append( V.output(attrs, header) )
AttributeError: 'unicode' object has no attribute 'output'
This happens because Cookie.py in the 2.6.4 stdlib has a bug that is fixed in later versions:
http://bugs.python.org/issue5275
http://hg.python.org/cpython/rev/c51721d64451/
Maybe that cookie[k] = v
code can be used as a workaround for older versions of python.
Current version uses flask.json.econder.encode_basestring, but 'encoder' no longer exists in the flask.json module, could potentially use flask.json._json.encoder, but that feels a little hacky.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.