Can not read cookies
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
import uvicorn
from typing import Optional
from fastapi import FastAPI, Response, Cookie
app = FastAPI()
@app.get("/set")
async def create_cookie(response: Response):
response.set_cookie(key="fakesession", value="fake-cookie-session-value")
return {"message": "Come to the dark side, we have cookies"}
@app.get("/read")
async def read_items(ads_id: Optional[str] = Cookie(None)):
return {"ads_id": ads_id}
if __name__ == "__main__":
uvicorn.run(app, port=80)
Description
When access /read ,I got {"ads_id": null}
Operating System
Windows
Operating System Details
Winodws 11
FastAPI Version
0.70.0
Python Version
Python 3.9.7
Additional Context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Can't access cookies from document.cookie in JS, but browser ...
You are most likely dealing with httponly cookies. httponly is a flag you can set on cookies meaning they can not be accessed...
Read more >Turn cookies on or off - Computer - Google Account Help
On your computer, open Chrome. · At the top right, click More More and then Settings. · Under "Privacy and security," click Site...
Read more >Enable cookies in your web browser
Click "Site Settings". Click "Cookies and site data". In the Privacy and security section, click Content Settings. Click the slider to "Allow ...
Read more >7 Keys to the Mystery of a Missing Cookie
7 Keys to the Mystery of a Missing Cookie · 1. SameSite attribute Defaults to Lax · 2. withCredentials is not Set to...
Read more >Cookies, document.cookie - The Modern JavaScript Tutorial
If you run it, then probably you'll see multiple cookies. That's because the document.cookie= operation does not overwrite all cookies. It only ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@libra146 Additionally if your cookie’s key is something like
X-Token
(with a dash in it), you need to read it asx_token
Your variable’s name must be the same as your cookie’s key e.g. in the example I provided above if you would like to read
fakesession
in cookies you have to make your code be like :