prometheus_flask_exporter
prometheus_flask_exporter copied to clipboard
🐞 TypeError: The view function for 'main' did not return a valid response.
Did it like described in https://github.com/rycus86/prometheus_flask_exporter#usage but with app.run(debug=True)
at the end? 🤔
> curl localhost:5000
<!doctype html>
<html lang=en>
<head>
<title>TypeError: The view function for 'main' did not return a valid response. The function either returned None or ended without a return statement.
// Werkzeug Debugger</title>
<link rel="stylesheet" href="?__debugger__=yes&cmd=resource&f=style.css">
<link rel="shortcut icon"
href="?__debugger__=yes&cmd=resource&f=console.png">
<script src="?__debugger__=yes&cmd=resource&f=debugger.js"></script>
<script>
var CONSOLE_MODE = false,
EVALEX = true,
EVALEX_TRUSTED = false,
SECRET = "Vdo3qNNRy8n4S2jNd334";
</script>
</head>
<body style="background-color: #fff">
<div class="debugger">
<h1>TypeError</h1>
<div class="detail">
<p class="errormsg">TypeError: The view function for 'main' did not return a valid response. The function either returned None or ended without a return statement.
</p>
</div>
<h2 class="traceback">Traceback <em>(most recent call last)</em></h2>
<div class="traceback">
<h3></h3>
<ul><li><div class="frame" id="frame-4369751440">
<h4>File <cite class="filename">"/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py"</cite>,
line <em class="line">2095</em>,
in <code class="function">__call__</code></h4>
<div class="source "><pre class="line before"><span class="ws"> </span>def __call__(self, environ: dict, start_response: t.Callable) -> t.Any:</pre>
<pre class="line before"><span class="ws"> </span>"""The WSGI server calls the Flask application object as the</pre>
<pre class="line before"><span class="ws"> </span>WSGI application. This calls :meth:`wsgi_app`, which can be</pre>
<pre class="line before"><span class="ws"> </span>wrapped to apply middleware.</pre>
<pre class="line before"><span class="ws"> </span>"""</pre>
<pre class="line current"><span class="ws"> </span>return self.wsgi_app(environ, start_response)</pre></div>
</div>
<li><div class="frame" id="frame-4369752336">
<h4>File <cite class="filename">"/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py"</cite>,
line <em class="line">2080</em>,
in <code class="function">wsgi_app</code></h4>
<div class="source "><pre class="line before"><span class="ws"> </span>try:</pre>
<pre class="line before"><span class="ws"> </span>ctx.push()</pre>
<pre class="line before"><span class="ws"> </span>response = self.full_dispatch_request()</pre>
<pre class="line before"><span class="ws"> </span>except Exception as e:</pre>
<pre class="line before"><span class="ws"> </span>error = e</pre>
<pre class="line current"><span class="ws"> </span>response = self.handle_exception(e)</pre>
<pre class="line after"><span class="ws"> </span>except: # noqa: B001</pre>
<pre class="line after"><span class="ws"> </span>error = sys.exc_info()[1]</pre>
<pre class="line after"><span class="ws"> </span>raise</pre>
<pre class="line after"><span class="ws"> </span>return response(environ, start_response)</pre>
<pre class="line after"><span class="ws"> </span>finally:</pre></div>
</div>
<li><div class="frame" id="frame-4369752560">
<h4>File <cite class="filename">"/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py"</cite>,
line <em class="line">2077</em>,
in <code class="function">wsgi_app</code></h4>
<div class="source "><pre class="line before"><span class="ws"> </span>ctx = self.request_context(environ)</pre>
<pre class="line before"><span class="ws"> </span>error: t.Optional[BaseException] = None</pre>
<pre class="line before"><span class="ws"> </span>try:</pre>
<pre class="line before"><span class="ws"> </span>try:</pre>
<pre class="line before"><span class="ws"> </span>ctx.push()</pre>
<pre class="line current"><span class="ws"> </span>response = self.full_dispatch_request()</pre>
<pre class="line after"><span class="ws"> </span>except Exception as e:</pre>
<pre class="line after"><span class="ws"> </span>error = e</pre>
<pre class="line after"><span class="ws"> </span>response = self.handle_exception(e)</pre>
<pre class="line after"><span class="ws"> </span>except: # noqa: B001</pre>
<pre class="line after"><span class="ws"> </span>error = sys.exc_info()[1]</pre></div>
</div>
<li><div class="frame" id="frame-4369752224">
<h4>File <cite class="filename">"/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py"</cite>,
line <em class="line">1526</em>,
in <code class="function">full_dispatch_request</code></h4>
<div class="source "><pre class="line before"><span class="ws"> </span>rv = self.preprocess_request()</pre>
<pre class="line before"><span class="ws"> </span>if rv is None:</pre>
<pre class="line before"><span class="ws"> </span>rv = self.dispatch_request()</pre>
<pre class="line before"><span class="ws"> </span>except Exception as e:</pre>
<pre class="line before"><span class="ws"> </span>rv = self.handle_user_exception(e)</pre>
<pre class="line current"><span class="ws"> </span>return self.finalize_request(rv)</pre>
<pre class="line after"><span class="ws"></span> </pre>
<pre class="line after"><span class="ws"> </span>def finalize_request(</pre>
<pre class="line after"><span class="ws"> </span>self,</pre>
<pre class="line after"><span class="ws"> </span>rv: t.Union[ResponseReturnValue, HTTPException],</pre>
<pre class="line after"><span class="ws"> </span>from_error_handler: bool = False,</pre></div>
</div>
<li><div class="frame" id="frame-4369751328">
<h4>File <cite class="filename">"/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py"</cite>,
line <em class="line">1545</em>,
in <code class="function">finalize_request</code></h4>
<div class="source "><pre class="line before"><span class="ws"> </span>with the `from_error_handler` flag. If enabled, failures in</pre>
<pre class="line before"><span class="ws"> </span>response processing will be logged and otherwise ignored.</pre>
<pre class="line before"><span class="ws"></span> </pre>
<pre class="line before"><span class="ws"> </span>:internal:</pre>
<pre class="line before"><span class="ws"> </span>"""</pre>
<pre class="line current"><span class="ws"> </span>response = self.make_response(rv)</pre>
<pre class="line after"><span class="ws"> </span>try:</pre>
<pre class="line after"><span class="ws"> </span>response = self.process_response(response)</pre>
<pre class="line after"><span class="ws"> </span>request_finished.send(self, response=response)</pre>
<pre class="line after"><span class="ws"> </span>except Exception:</pre>
<pre class="line after"><span class="ws"> </span>if not from_error_handler:</pre></div>
</div>
<li><div class="frame" id="frame-4369752448">
<h4>File <cite class="filename">"/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py"</cite>,
line <em class="line">1701</em>,
in <code class="function">make_response</code></h4>
<div class="source "><pre class="line before"><span class="ws"> </span>" (body, status), or (body, headers)."</pre>
<pre class="line before"><span class="ws"> </span>)</pre>
<pre class="line before"><span class="ws"></span> </pre>
<pre class="line before"><span class="ws"> </span># the body must not be None</pre>
<pre class="line before"><span class="ws"> </span>if rv is None:</pre>
<pre class="line current"><span class="ws"> </span>raise TypeError(</pre>
<pre class="line after"><span class="ws"> </span>f"The view function for {request.endpoint!r} did not"</pre>
<pre class="line after"><span class="ws"> </span>" return a valid response. The function either returned"</pre>
<pre class="line after"><span class="ws"> </span>" None or ended without a return statement."</pre>
<pre class="line after"><span class="ws"> </span>)</pre>
<pre class="line after"><span class="ws"></span> </pre></div>
</div>
</ul>
<blockquote>TypeError: The view function for 'main' did not return a valid response. The function either returned None or ended without a return statement.
</blockquote>
</div>
<div class="plain">
<p>
This is the Copy/Paste friendly version of the traceback.
</p>
<textarea cols="50" rows="10" name="code" readonly>Traceback (most recent call last):
File "/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py", line 2095, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py", line 2080, in wsgi_app
response = self.handle_exception(e)
File "/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app
response = self.full_dispatch_request()
File "/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py", line 1526, in full_dispatch_request
return self.finalize_request(rv)
File "/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py", line 1545, in finalize_request
response = self.make_response(rv)
File "/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py", line 1701, in make_response
raise TypeError(
TypeError: The view function for 'main' did not return a valid response. The function either returned None or ended without a return statement.
</textarea>
</div>
<div class="explanation">
The debugger caught an exception in your WSGI application. You can now
look at the traceback which led to the error. <span class="nojavascript">
If you enable JavaScript you can also use additional features such as code
execution (if the evalex feature is enabled), automatic pasting of the
exceptions and much more.</span>
</div>
<div class="footer">
Brought to you by <strong class="arthur">DON'T PANIC</strong>, your
friendly Werkzeug powered traceback interpreter.
</div>
</div>
<div class="pin-prompt">
<div class="inner">
<h3>Console Locked</h3>
<p>
The console is locked and needs to be unlocked by entering the PIN.
You can find the PIN printed out on the standard output of your
shell that runs the server.
<form>
<p>PIN:
<input type=text name=pin size=14>
<input type=submit name=btn value="Confirm Pin">
</form>
</div>
</div>
</body>
</html>
<!--
Traceback (most recent call last):
File "/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py", line 2095, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py", line 2080, in wsgi_app
response = self.handle_exception(e)
File "/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app
response = self.full_dispatch_request()
File "/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py", line 1526, in full_dispatch_request
return self.finalize_request(rv)
File "/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py", line 1545, in finalize_request
response = self.make_response(rv)
File "/Users/tgotwig/.asdf/installs/python/3.10.5/lib/python3.10/site-packages/flask/app.py", line 1701, in make_response
raise TypeError(
TypeError: The view function for 'main' did not return a valid response. The function either returned None or ended without a return statement.
-->
I should probably update those examples to return something valid, sorry. 🤦 As the error message explains:
The function either returned None or ended without a return statement.
If you change the pass
to something like return 'OK'
then it should work.