1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] A script using the requests module produces a 428 status code

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I've created a script to issue a POST HTTP request with appropriate parameters, generated upon complying with the fields shown in this image, to this website. The script is supposed to produce a 200 status code, indicating that the response I received from the server was successful.

    However, when I run the script, I always get a 428 status code in the second request. How can I fix the issue? Here is the script for your consideration:

    import requests

    url = 'https://wizzair.com/en-gb'
    link = 'https://be.wizzair.com/24.9.0/Api/search/search'

    payload = {"isFlightChange":False,"flightList":[{"departureStation":"TIA","arrivalStation":"VIE","departureDate":"2024-09-17"},{"departureStation":"VIE","arrivalStation":"TIA","departureDate":"2024-10-20"}],"adultCount":1,"childCount":0,"infantCount":0,"wdc":True}

    headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'Accept-Encoding': 'gzip, deflate, br, zstd',
    'Accept-Language': 'en-US,en;q=0.9',
    'Host': 'wizzair.com',
    'Referer': 'https://wizzair.com/en-gb',
    }

    with requests.Session() as session:
    session.headers.update(headers)
    r = session.get(url)
    print(r.status_code)
    session.headers['Accept'] = 'application/json, text/plain, */*'
    session.headers['Referer'] = 'https://wizzair.com/en-gb/booking/select-flight/TIA/VIE/2024-09-17/2024-10-20/1/0/0/null'
    session.headers['Host'] = 'be.wizzair.com'
    session.headers['Origin'] = 'https://wizzair.com'
    resp = session.post(link,json=payload)
    print(resp.status_code)

    Continue reading...

Compartilhe esta Página