简体   繁体   中英

How do i go about post a request with python

so i was just in the process of check the voters list for my country and i wanted to write a scrite to do, but u am getting this error. Error Fetching http headers

here is my code :

import requests
headers = {'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-       requests/2.17.3', 'Connection': 'keep-alive'}



url = 'https://ecj.com.jm/wp-content/themes/electorial/inc/voters-list-query.php'


kool = { 'FirstName' : 'john', 'LastName' : 'doe', 'DateOfBirth' : '18/12/1998' }

print('getting ready to send data')
x = requests.post(url, data = kool, headers=headers)
print('data sent.. waiting on response')


print(x.text)

and here is the ajax code i pulled from the website:

 request_url = "https://ecj.com.jm/wp-content/themes/electorial/inc/voters-list-query.php";

        serialized_form = $( this ).serializeArray();
        jsonForm = JSON.stringify( serialized_form );
        form_obj = JSON.parse( jsonForm );

        $.ajax({
            url: request_url,
            method: "POST",
            data: { 'FirstName' : form_obj[0]['value'], 'LastName' : form_obj[1]['value'], 'DateOfBirth' : form_obj[2]['value'] },
            dataType: "json",
            success: function( data ) {
                clearOutput();
                processResponse( data )

The error is server-side. I guess request is missing Content-Type header. Try adding "Content-Type": "application/json"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM