douba6361 2017-11-13 13:38
浏览 47
已采纳

MySQL DB,通过Python-PHP将多个数据发送到服务器

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!

  • 写回答

1条回答 默认 最新

  • dongwei7048 2017-11-13 13:42
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建