0

I'm using requests library for test my Flask application.

When I'm sending request

sess = requests.Session()
sess.post(
    url=SERVER_URL + '/login',
    data={
        'email': 'chel',
        'password': '1',
        'remember_me': True,
        'csrf_token': BeautifulSoup(requests.get(SERVER_URL + '/login').content, "html.parser").find('input', {'id': 'csrf_token'})['value']
    }
)

And then print received cookies on side of server

@app.route('/login', methods=['GET', 'POST'])
def login():
    print(request.cookies)

I getting empty cookies ImmutableMultiDict([]), but when I'm making request from browser my server outputs ImmutableMultiDict([('session', '(some data)')])

davidism
  • 121,510
  • 29
  • 395
  • 339
Magprone
  • 23
  • 6
  • Does this answer your question? [How to send cookies in a post request with the Python Requests library?](https://stackoverflow.com/questions/7164679/how-to-send-cookies-in-a-post-request-with-the-python-requests-library) – Nick Bailey Apr 20 '22 at 16:58
  • @NickBailey I tried and it works, but in this method you are constantly overwriting cookies and not using the Session object. Is there a way to use session with properly functioning cookies? – Magprone Apr 20 '22 at 17:33

0 Answers0