TypeError
TypeError: 'function' object is not subscriptable
Traceback (most recent call last)
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", line 39, in reraise
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", line 39, in reraise
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\BaumK\Documents\Programiren\ZeiterfassungRondo\Main.py", line 18, in sessions
return "Hallo" + escape(sessions['name'])
TypeError: 'function' object is not subscriptable
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.
You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:
dump()
shows all variables in the framedump(obj)
dumps all that's known about the object
Dass ist die Fehlermeldung
from flask import Flask, url_for , request , redirect , make_response,escape,session
from werkzeug.utils import secure_filename
import os
folder = "C:\\Users\\BaumK\\Documents\\Programiren\\ZeiterfassungRondo\\Uplods"
extension = set (['txt','jpg','png'])
app = Flask(__name__)
def allowed(filename):
return '.' in filename and filename.rsplit('.',1)[1].lower() in extension
@app.route("/" , methods=["GET","POST"])
def sessions():
if request.method == 'POST':
session['name'] = request.form['name']
return redirect(request.url)
else:
if 'name'in session:
return "Hallo" + escape(sessions['name'])
else:
return '''
<form method="post">
<p><input type="text" name="name"></p>
<p><input type="submit" value="submit"></p>
</form>
'''
app.secret_key = "\x07\x80\x1c^\x02\x16\xedqGS\xe0\x0c.v\xec\x8d==\xce\x15\xd4e\xea\xbe"
@app.route("/upload", methods=["GET","POST"])
def index():
if request.method == 'POST' :
if 'file' not in request.files:
return redirect(request.url)
file = request.files['file']
if file.filename == '' :
return redirect(request.ur)
if allowed(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(folder,filename))
return redirect(request.url)
return '''
<h1>Upload</h1>
<form method="post" enctype="multipart/form-data">
<p><input type="file" name="file"></p>
<p><input type="submit" name="submit"></p>
</form>
'''
@app.route("/login", methods=["GET","POST"])
def login ():
cookie = request.cookies.get('username')
if cookie is not None :
return "Hallo " + cookie
if request.method == 'POST':
name=request.form['name']
else:
name=request.args.get('name')
resp = make_response("Hello "+name+"!")
resp.set_cookie('username' , name)
return resp
if __name__ == '__main__':
app.run(port=3254 , debug=True)
Display More
Und dass ist das Script.
In der Kommandozeile steht noch das hier
C:\Users\BaumK\AppData\Local\Programs\Python\Python38\python.exe C:/Users/BaumK/Documents/Programiren/ZeiterfassungRondo/Main.py
* Serving Flask app "Main" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Restarting with stat
* Debugger is active!
* Debugger PIN: 109-777-029
* Running on http://"IP"/ (Press CTRL+C to quit)
127.0.0.1 - - [16/Jul/2020 18:46:30] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\BaumK\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\BaumK\Documents\Programiren\ZeiterfassungRondo\Main.py", line 18, in sessions
return "Hallo" + escape(sessions['name'])
TypeError: 'function' object is not subscriptable
127.0.0.1 - - [16/Jul/2020 18:46:30] "GET /?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
127.0.0.1 - - [16/Jul/2020 18:46:30] "GET /?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
127.0.0.1 - - [16/Jul/2020 18:46:30] "GET /?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1" 200 -
127.0.0.1 - - [16/Jul/2020 18:46:30] "GET /?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1" 200 -
127.0.0.1 - - [16/Jul/2020 18:46:30] "GET /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
127.0.0.1 - - [16/Jul/2020 18:46:31] "GET /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
Display More