Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
Pass cookie header with Flask test client request

I am having trouble getting the Flask test client to pass cookies. This code used to work and I presume something in my environment changed, which breaks this. I recently created a new Python 3.7 virtualenv and installed Flask 1.0.2.

from flask import Flask, jsonify, request

app = Flask(__name__)


@app.route('/cookie_echo')
def cookie_echo():
    return jsonify(request.cookies)


with app.test_client() as client:
    response = client.get("/cookie_echo", headers={"Cookie": "abc=123; def=456"})
    print(response.get_data(as_text=True))

Running the example prints {}, but I expect it to print {"abc":"123","def":"456"}.

If I run my app via flask run, sending headers with curl works:

$ curl -H "Cookie: abc=123; def=456" http://localhost:5000/cookie_echo
{"abc":"123","def":"456"}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The Client manages cookies, you should not pass them manually in headers={}. Due to changes in Werkzeug 0.15, passing a Cookie header manually, which was not intended, no longer works. Use client.set_cookie to set a cookie, or set the cookie in a response and it will be sent with the next request.

c = app.test_client()
c.set_cookie('localhost', 'abc', '123')
c.set_cookie('localhost', 'def', '456')
c.get('/cookie_echo')
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda