Skip to content

Instantly share code, notes, and snippets.

@DazWorrall
Created October 1, 2012 10:35
Show Gist options
  • Save DazWorrall/3810824 to your computer and use it in GitHub Desktop.
Save DazWorrall/3810824 to your computer and use it in GitHub Desktop.
Raven error when client disconnects on async server
$ pip install flask blinker raven gunicorn gevent
...
$ gunicorn -k gevent test:app
2012-10-01 11:16:57 [62111] [INFO] Starting gunicorn 0.14.6
2012-10-01 11:16:57 [62111] [INFO] Listening at: http://127.0.0.1:8000 (62111)
2012-10-01 11:16:57 [62111] [INFO] Using worker: gevent
2012-10-01 11:16:57 [62112] [INFO] Booting worker with pid: 62112
2012-10-01 11:26:00 [62292] [ERROR] Error handling request
Traceback (most recent call last):
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/gunicorn/workers/async.py", line 44, in handle
self.handle_request(req, client, addr)
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/gunicorn/workers/ggevent.py", line 88, in handle_request
super(GeventWorker, self).handle_request(*args)
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/gunicorn/workers/async.py", line 78, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/flask/app.py", line 1701, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/flask/app.py", line 1689, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/flask/app.py", line 1277, in handle_exception
got_request_exception.send(self, exception=e)
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/blinker/base.py", line 267, in send
for receiver in self.receivers_for(sender)]
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/raven/contrib/flask/__init__.py", line 82, in handle_exception
data=get_data_from_request(request),
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/raven/contrib/flask/utils.py", line 14, in get_data_from_request
'data': request.form,
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/werkzeug/local.py", line 336, in __getattr__
return getattr(self._get_current_object(), name)
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/werkzeug/utils.py", line 77, in __get__
value = self.func(obj)
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/werkzeug/wrappers.py", line 383, in form
self._load_form_data()
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/flask/wrappers.py", line 129, in _load_form_data
RequestBase._load_form_data(self)
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/werkzeug/wrappers.py", line 318, in _load_form_data
data = parser.parse_from_environ(self.environ)
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/werkzeug/formparser.py", line 164, in parse_from_environ
return self.parse(stream, mimetype, content_length, options)
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/werkzeug/formparser.py", line 188, in parse
content_length, options)
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/werkzeug/formparser.py", line 100, in wrapper
stream.exhaust()
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/werkzeug/wsgi.py", line 787, in exhaust
self.read(chunk)
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/werkzeug/wsgi.py", line 805, in read
return self.on_disconnect()
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/werkzeug/wsgi.py", line 773, in on_disconnect
raise ClientDisconnected()
ClientDisconnected: 400: Bad Request
^C2012-10-01 11:26:39 [62292] [INFO] Worker exiting (pid: 62292)
#!/usr/bin/env python
from flask import Flask, request, Request
from raven.contrib.flask import Sentry
class BadFile(object):
def write(self, *args, **kwargs):
raise IOError('Boom')
class FileRequest(Request):
def _get_file_stream(self, total_content_length, content_type, filename=None, content_length=None):
return BadFile()
app = Flask(__name__)
app.debug = True
app.request_class = FileRequest
sentry = Sentry(app, dsn='http://public_key:secret_key@example.com/1')
blob = '''
<html>
<body>
<form enctype="multipart/form-data" method="POST">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
'''
@app.route('/', methods=['GET', 'POST'])
def handle():
if request.method == 'POST':
f = request.files['file']
return blob
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment