Michael Scarpa
Michael Scarpa

Reputation: 121

Passing data from Python POST request to PHP

Using PHP Laravel 5. Can't seem to find out how to do this specific thing. I have data in a python script. Running a python command will post successfully to my PHP method and will execute the following when i hard code api key and secret.

    $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.

    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?

Thanks!

Upvotes: 0

Views: 1157

Answers (1)

wenzul
wenzul

Reputation: 4058

May you mean reading the $_POST parameters?

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

Upvotes: 1

Related Questions