Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python等价于PHP Post_Php_Python - Fatal编程技术网

Python等价于PHP Post

Python等价于PHP Post,php,python,Php,Python,我正在使用遗留系统,而以前的程序员已经离开了。这是他留下的测试,我不知道如何使用Python模拟他的测试 下面是test.php var tHost = "10.1.10.123"; var tExiname = "CloudHM TEST123"; var tIncname = "INC012345"; var tHWname = "aa 1111 0"; var tHwattr = "all"; var tStatus = 0; var tCteatedat = "2016-05-23 12

我正在使用遗留系统,而以前的程序员已经离开了。这是他留下的测试,我不知道如何使用Python模拟他的测试

下面是
test.php

var tHost = "10.1.10.123";
var tExiname = "CloudHM TEST123";
var tIncname = "INC012345";
var tHWname = "aa 1111 0";
var tHwattr = "all";
var tStatus = 0;
var tCteatedat = "2016-05-23 12:20:42";
var d = new Date,
tUpdateat = [d.getFullYear(),
             d.getMonth()+1,
             d.getDate()].join('-')+' '+
          [d.getHours(),
           d.getMinutes(),
           d.getSeconds()].join(':');
var arr =  [{ host: tHost, host_name: tExiname, component_type: tHWname, component_status: tStatus, incident_created: tUpdateat }];
var arr2 =JSON.stringify(arr)
$.ajax({
    url: 'http://customer.beenets.net/api/cloudhm/api.php' ,
    type: 'POST',
    data: { params: arr2 },
    success: function(msg) {
        //ShowOutput(msg);
        alert(JSON.stringify(arr, null, 4));
    }
})
我试过这个。响应为
200
,但PHP服务器未读取有效负载

notification_data = [{
            "host": i.host,
            "host_name": i.host_name,
            "incident_created": i.incident_created,
            "component_type": i.component_type,
            "component_status": i.component_status
        }]
        response = requests.post(NOC_BEENETS_URL, data=json.dumps(notification_data))
然后我试着把
params
键放在它前面

notification_data = [{
    "params":{
        "host": i.host,
        "host_name": i.host_name,
        "incident_created": i.incident_created,
        "component_type": i.component_type,
        "component_status": i.component_status
    }
}]
response = requests.post(NOC_BEENETS_URL, data=json.dumps(notification_data))
服务器返回我200并再次读取无有效负载。

编辑:

notification_data = [{
        "host": i.host,
        "host_name": i.host_name,
        "incident_created": i.incident_created,
        "component_type": i.component_type,
        "component_status": i.component_status
    }]
r = requests.post(NOC_BEENETS_URL, data = {'params': json.dumps(notification_data)})

test.php
中,您有JavaScript代码,而不是php代码-因此您不需要php来运行它:)我想您需要
data={“params”:json.dumps(…)}
@furas请稍等。它很遥远editing@furasPHP legacy现在可以读取我的负载了。谢谢
furas
:-)不工作。它对我的反应是
200
。确认我在这里有有效负载的是
pdb
(pdb)response.content'{“response\u data”:{“host”:“10.0.34.1”,“component\u status”:“0”,“host\u name”:“LMD718”,“component\u type”:“server”,“incident\u created”:“2016-10-03 17:59:45”;“response\u datetime”:“2016-10-12 16:18:18”}谢谢你,它能工作。我刚找到你在furas后编辑的评论