English 中文(简体)
不能确定的会议变量
原标题:Python (Flask) Session variables not being set
  • 时间:2024-02-11 17:06:40
  •  标签:
  • python
  • flask

我有这一法典:

sD = await db.session.getChatbotDetails(request.json.get("apiKey"))
if sD:
   setSessionDetails(sD.get_json(), request.json.get("apiKey"))```

之后:

def setSessionDetails(sD, api_key):
    session["company_name"] = sD["company_name"]
    session["api_key"] = api_key
    session["website_url"] = sD["website_url"]
    session["welcome_prompt"] = sD["welcome_prompt"]

但是,当时,例如,我只读了吗?

@app.route("/chat", methods=["POST"])
async def chat():
    print(session)
    if isAuth(request.json.get("apiKey"), "https://website_url") == 200:
    

因此,它搁置了本届会议的价值观。

问题回答

在使用<<条码>/代码>时,需要了解的一个方面是,Flavisk储存使用 co具的信息,正如它在文件中所述:

关于基于烹饪的会议的说明: 弗拉茨克将采用你对本届会议表示反对的价值观,并将其编为 co。 如果你发现一些价值观在各种要求中并不坚持,那么,厨师确实是能够做到的,而且你并没有获得一个明确的错误信息,因此,与网络浏览器所支持的规模相比,你在网页答复中检查了厨师的规模。

我怀疑,如果你在本届会议上只储存这一信息,情况就是如此。 但是,如果你储存大量信息,值得检查。


Another possibility is that, you didn t mention how are you making requests to Flask. Like I said in the previous point, session uses cookie to store information and read from it. If you aren t persisting cookies between requests then session is going to be empty as you are seeing.

例如,请指出您有<代码>ppy。

from flask import Flask, session

app = Flask(__name__)
app.secret_key = b"A SECRET"


@app.route("/")
def index():
    session["company_name"] = "A company name"
    session["api_key"] = "An API key"
    session["website_url"] = "https://example.com/business"
    session["welcome_prompt"] = "Welcome!"
    return "Stored cookies"


@app.route("/cookies")
def read_cookies():
    return str(session)


if __name__ == "__main__":
    app.run(debug=True)

如果我们利用治疗方法进行询问 Flask, Un storing cookies between demand, when calls /cookies endpoint, it should be food.

$ curl http://localhost:5000/
Stored cookies
$ curl http://localhost:5000/cookies
<SecureCookieSession {}>

现在,我们应当努力在请求之间储存厨师和阅读厨师。

# Store cookies in a file named  flask-cookies 

$ curl -c flask-cookies http://localhost:5000/
Stored cookies
$ curl -b flask-cookies http://localhost:5000/cookies
<SecureCookieSession { api_key :  An API key ,  company_name :  A company name ,
  website_url :  https://example.com/business ,  welcome_prompt :  Welcome! }>




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签