Python POST sql查询结果

2024-10-02 18:23:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我想把一堆结果发送到服务器。你知道吗

cur.execute('SELECT a,b,c,b FROM wicap WHERE a.num > 600 limit 25')
r = cur.fetchall()

此时r为:

[(1487590224, 1487614532, -75, -41, 504, -73),
(1487596562, 1487614915, -75, -59, 156, -75),...]

我想做一些类似的事情:

response = urllib2.urlopen('http://example.com/post/', data=r)

在服务器端,您可以通过以下方式获取数据:

def POST()
data = web.data()
for record in data...

然后在服务器上处理查询结果。你知道吗

urlencode失败,出现ValueError:要解压缩的值太多 我试过用res=[dict]创建一个json((当前描述[i] [0],value)对于i,value in enumerate(row))对于r]中的行 但是f=urllib2.urlopen(\u url,res)返回TypeError:必须是string或buffer,而不是list

欢迎有想法!你知道吗


Tags: infrom服务器executedatavalueresurllib2
1条回答
网友
1楼 · 发布于 2024-10-02 18:23:36

您需要使用json.dumps将数据编码为json:

import json


r = [(1487590224, 1487614532, -75, -41, 504, -73), (1487596562, 1487614915, -75, -59, 156, -75)]
response = urllib2.urlopen('http://example.com/post/', data=json.dumps(r))

相关问题 更多 >