简体   繁体   English

将数据从Python POST请求传递到PHP

[英]Passing data from Python POST request to PHP

Using PHP Laravel 5. Can't seem to find out how to do this specific thing. 使用PHP Laravel5。似乎无法找到具体方法。 I have data in a python script. 我在python脚本中有数据。 Running a python command will post successfully to my PHP method and will execute the following when i hard code api key and secret. 运行python命令将成功发布到我的PHP方法,并在我硬编码api密钥和密码时执行以下命令。

    $api_key = 1;
    $api_secret = 'sesame';

    //if api id and secret match, get oldest job with available timestamp before current time with status of 0

    if ($api_key == 1 and $api_secret == 'sesame') {

        $current_dt = '';
        $current_dt = date('Y.m.d H:i:s');

        $first_job_that_qualifies = \App\Job::orderBy('created_at', 'desc')
            ->where('status', 0)
            ->where('available_ts', '<', $current_dt)
            ->first();

        if ($first_job_that_qualifies != null){

            $first_job_that_qualifies->status = 1;
            $first_job_that_qualifies->save();
        }


    }


    }

Now i would like to take the hard-coded values away and check them with the data I'm passing from python. 现在,我想删除硬编码的值,并用我从python传递的数据检查它们。

    data = {
        'api_key': api_key,
        'api_secret': api_secret,
        }

    print data

    r = requests.post(quasar_url, data=data)
    print r.text

How would I call that dictionary "data" from python in my PHP function so I can use that in my initial if statement? 如何在PHP函数中从python调用该字典“数据”,以便可以在我的初始if语句中使用它?

Thanks! 谢谢!

您是否可以阅读$_POST参数?

if ($api_key == $_POST['api_key'] and $api_secret == $_POST['api_secret']) {

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

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