Im new to Python/Flask and wanted to set Cookies for my Website. When i open the Website i get this error.
The functions that are causing Problems:
def numberinstring(nr: int, cookie: str):
visited = cookie.split(":")
for door in visited:
if nr == int(door):
return True
return False
def handlecookie(resp: Response, nr: int):
cookie = request.cookies.get("Besucht")
if cookie is None:
resp.set_cookie("Besucht", str(nr))
return resp
if numberinstring(nr, cookie):
return resp
resp.set_cookie("Besucht",cookie + ":" + str(nr))
return resp
I am confused to why it doesent work as I checked if cookie is None in line 15.
The Traceback:
File "C:\Users\PJ\Desktop\Kalender\main.py", line 48, in start
if numberinstring(i, cookie):
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\PJ\Desktop\Kalender\main.py", line 12, in numberinstring
visited = cookie.split(":")
^^^^^^^^^^^^
Can somebody help me with this?
if cookie is None
should have worked, and prevents passingNone
to thenumberinstring
function. Are you sure those changes were properly applied and your server is up to date? You can be doubly-sure by going through a debugger or putting debug logs after the.get
call, inside theif None
check, and insidenumberinstring
.