简体   繁体   English

我如何使用 python 发布请求

[英]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获取 http 标头时出错

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:这是我从网站上提取的ajax代码:

 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.我猜请求缺少Content-Type标头。 Try adding "Content-Type": "application/json"尝试添加"Content-Type": "application/json"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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