烧瓶会话cookie更改数据类型
我正在为Python的数据库构建一个Web应用程序,其中托管在Pythonanywhere上。
到目前为止,该应用程序已拥有版本1所需的一切,包括菜单,表单,日志记录和一些基本的用烧瓶login的基本用户认证。 只要您从新鲜的浏览器开始,并且在同一浏览器中不要切换用户,一切正常。
我能够将虫子指定到烧瓶上。 以某种方式,这种cookie基本上像词典一样,将其类型从< class'dict'>
转变为< class'werkzeug.local.local.localproxy'>
。我仍然可以像以前一样访问它,但是这两个cookie之间的数据并不相同,这会导致一些怪异的重定向。
烧瓶应用程序的创建如下:
app = flask.Flask(__name__)
app.secret_key = 'SUPER SECRET'
app.config.update(SESSION_COOKIE_SAMESITE="None", SESSION_COOKIE_SECURE=True, REMEMBER_COOKIE_SECURE = True)
app.run(debug=False, threaded=True)
将会话打印到控制台看起来与此相似。到目前为止,我无法在什么情况下确定输出变化
输出1
<SecureCookieSession {'Key1': 1,
'Key2': [{'Subkey1': 'value1', 'Subkey2': 'value2'}],
'_fresh': True,
'_id': 'loooooooooongstring,
'_user_id': 'someid'}>
输出2 ,
{'Key1': 2,
'Key2': [{'Subkey1': 'othervalue1', 'Subkey2': 'othervalue2'}]}
因为这两种选项的行为都像dict一样,很难检测到这种异常。 我什至不太介意我正在使用的是什么,但是这里的主要问题是它们没有相同的价值观。
一开始我认为这可能与不祥的有关flask.session.modified = true
语句,需要手动调用。但这到处都到位(可能过度杀伤)。
我愿意就如何解决此问题提出建议。也许我对应用程序的设置方式从根本上做错了。例如,离线版本似乎没有这个问题。
也许可以识别选项并不断反映它们?
编辑 打印的输出(f'cookie_type:{type(cookie)}')和print(type(cookie))是相同的。
I'm building a web application for a database in python with flask hosted on pythonanywhere.
By now the application has everything you might need for a version 1 including menu, forms, logging and a some basic user-authentication with flask-login.
Everything works fine as long as you start off with a fresh browser and don't switch users while in the same browser.
I was able to pinpoint the bug to the flask.session cookie.
Somehow this cookie, which basically behaves like a dictionary changes its type from <class 'dict'>
to <class 'werkzeug.local.LocalProxy'>
. I can still access it the same way as before, but the data between those two cookies is not the same which leads to some weird redirects.
The flask app is created as follows:
app = flask.Flask(__name__)
app.secret_key = 'SUPER SECRET'
app.config.update(SESSION_COOKIE_SAMESITE="None", SESSION_COOKIE_SECURE=True, REMEMBER_COOKIE_SECURE = True)
app.run(debug=False, threaded=True)
Printing the session to the console looks similiar to this. So far I was not able to identify under what circumstances the output changes
Output 1
<SecureCookieSession {'Key1': 1,
'Key2': [{'Subkey1': 'value1', 'Subkey2': 'value2'}],
'_fresh': True,
'_id': 'loooooooooongstring,
'_user_id': 'someid'}>
Output 2
{'Key1': 2,
'Key2': [{'Subkey1': 'othervalue1', 'Subkey2': 'othervalue2'}]}
Since both Options behave like a dict it was hard to detect this anomaly. I don't even really mind what I'm working with but the main issue here is that they dont hold the same values.
At first I thought it could have something to do with the ominous flask.session.modified = true
statement that needs to be called manually. But this is in place everywhere (probably overkill).
I'm open for suggestions on how to resolve this issue. Maybe I did something fundamentally wrong with the way the application is set up. For example the offline version doesn't seem to have this issue.
Maybe it is possible to identify both options and mirror them constantly?
Edits
The output of print(f'cookie_type: {type(cookie)}') and print(type(cookie)) is the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论