Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass data from python to php?

Tags:

python

I have tried this code(Python side)...

import requests
import json

keys = {"name": "John"}
headers = {'Content-type': 'application/x-www-form-urlencoded', 'Accept': 'text/plain'}

r = requests.post("http://localhost/Python_/test.php", data = keys, headers = headers)

print r.url
print r.status_code

On php side, I am trying to get the name..

print_r($_POST['keys']);

And I am getting this error.. Notice: Undefined index: keys in C:\xampp\htdocs\Python_\test.php on line 8

I tried it on REST client, the code shows the name on REST client but on localhost it got this error.

like image 443
Nevermore Avatar asked Oct 20 '25 13:10

Nevermore


1 Answers

Your post data will be the keys dictionary.
Your php code should be print_r($_POST['name']);

like image 73
Yash Mehrotra Avatar answered Oct 23 '25 04:10

Yash Mehrotra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!