Reputation: 117
I have a Virtual Machine/Web Server with MySQL up and running, and want to receive the data from client hardware that is saved in a .csv file, how can i do a python script to send it? i was recommended requests library from Python to send it and receive it through PHP POST. Problem is ive NEVER used PHP and HTML and so im a bit stuck with the interaction between the 2. Thanks a lot!
sample code is:
import csv
import requests
session = requests.Session()
with open('r01a2.csv','rb') as f:
reader = csv.reader(f)
for row in reader:
r = session.post('MyURL', data = {'date: row[0],'value': row[1]})
print r.text
Code on Server side is:
<?php
$formato = "INSERT INTO `datos_pruebas`.`Datos_Edison` (`id`, `date`, `pulse`) VALUES (NULL, '%s', '%f')";
$sql=sprintf($formato,$date,$pulse);
$enlace = mysql_connect('localhost','root','clinichub');
$resultado = mysql_query($sql,$enlace);
$id=NULL;
if(!empty($_POST))
{
echo htmlspecialchars($_POST["date"]);
} else {
echo "gg";
}
EDIT2: It finally worked after solutions gave by community and feedback, thanks a lot for your recommendations!
Upvotes: 0
Views: 100
Reputation: 153
Make sure the post in python uses the correct content-type and verify on the serverside php if $_FILES has an entry. (i.e. print_r($_FILES) ) should return your file, you won't find it in $_POST.
Upvotes: 1