[Python] Getting form results using python request

Discussão em 'Python' iniciado por Stack, Janeiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    Admittedly, this is my first time using requests. The form I'm attempting to use is here: https://trade.cbp.dhs.gov/ace/liquidation/LBNotice/

    Here is my code:

    import requests

    headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Content-Type': 'application/json; charset=UTF-8',
    'User-Agent': 'Mozilla/5.0',
    'X-Requested-With': 'XMLHttpRequest'
    }


    payload = {
    "dtPageVars":
    {
    "draw":1,
    "columns":
    [
    {"data":"postedDate","name":"","searchable":"true","orderable":"false","search":{"value":"","regex":"false"}},
    {"data":"eventDate","name":"","searchable":"true","orderable":"false","search":{"value":"","regex":"false"}},
    {"data":"voidedDate","name":"","searchable":"true","orderable":"false","search":{"value":"","regex":"false"}},
    {"data":"event","name":"","searchable":"true","orderable":"false","search":{"value":"","regex":"false"}},
    {"data":"basis","name":"","searchable":"true","orderable":"false","search":{"value":"","regex":"false"}},
    {"data":"action","name":"","searchable":"true","orderable":"false","search":{"value":"","regex":"false"}},
    {"data":"entryNumber","name":"","searchable":"true","orderable":"false","search":{"value":"","regex":"false"}},
    {"data":"portOfEntry","name":"","searchable":"true","orderable":"false","search":{"value":"","regex":"false"}},
    {"data":"entryDate","name":"","searchable":"true","orderable":"false","search":{"value":"","regex":"false"}},
    {"data":"entryType","name":"","searchable":"true","orderable":"false","search":{"value":"","regex":"false"}},
    {"data":"teamNumber","name":"","searchable":"true","orderable":"false","search":{"value":"","regex":"false"}}
    ],
    "order":[],
    "start":0,
    "length":100,
    "search":
    {
    "value":"",
    "regex":"false"
    }
    },
    "searchFields":
    {
    "portOfEntry":"0101",
    "entryType":"01"
    }
    }

    url = 'https://trade.cbp.dhs.gov/ace/liquidation/LBNotice/'
    searchUrl = 'https://trade.cbp.dhs.gov/ace/liquidation/LBNotice/search'

    response = requests.post(searchUrl, headers=headers, data=payload)

    print(response.status_code)


    I keep getting 500 status code but I am not sure why. Could it be the headers I'm using? I've tried many different combinations of headers without luck. Is it possible to use requests for this form or am I better off finding a different approach?

    Any help would truly be appreciated. Thank you.

    Continue reading...

Compartilhe esta Página