Flask cookie not set in Safari

I had strange behavior with my session cookie: launching a flash app on my Mac, everything works fine and a cookie is set in any browser.

However, if I run it on a Windows server, the session cookie is not set on Safari (and iOS), but still works with any other browsers. How can this happen? Here's an example of a simple application:

import os
import uuid
from flask import Flask, render_template, session

app = Flask(__name__)

SESSION_LIFETIME = 3600

@app.before_request
def before_request():

    # create session
    if not session.get('uid'):
        session.permanent = True
        session['uid'] = uuid.uuid4()

@app.route('/', methods=['GET'])
def test():

    return render_template('test.html')

if __name__ == "__main__":
    app.secret_key = os.urandom(24)
    app.permanent_session_lifetime = SESSION_LIFETIME
    app.debug = True
    app.run(threaded=True,
            host="0.0.0.0",
            port=int("5000")
            )

      

with an example test.html:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Wubwub</title>
</head>
<body>
Jojo
</body>
</html>

      

Why does it work in any browser but not (essential) Safari? And why does the same code work when run on my mac (accessed from both external and local) but not on windows? All other browsers work with windows (even outside).

+3


source to share


1 answer


I had the same behavior that the session variables were not working the way they wanted.

So, I removed the use of the session and did the job like a session. I usedlist with key-value pair

First run the list



 list_name = {'key1':'','key2':''};  and so on...

      

And store the variables as you want in this list and access them wherever you want by replacing the keys

+1


source







All Articles