Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 如何通过循环记录向服务器发送单个POST请求?_Sql Server_Json_Python Requests_Pyodbc - Fatal编程技术网

Sql server 如何通过循环记录向服务器发送单个POST请求?

Sql server 如何通过循环记录向服务器发送单个POST请求?,sql-server,json,python-requests,pyodbc,Sql Server,Json,Python Requests,Pyodbc,我有一个SQL表,我正在循环通过它向服务器发送每个记录的单个post请求。所有记录应为单独的JSON 我期待着这样的事情: while there are rows in table: write the number of rows as json and output files. while there are rows being written as jsons and output files: server is pinged for the number of jsons an

我有一个SQL表,我正在循环通过它向服务器发送每个记录的单个post请求。所有记录应为单独的JSON

我期待着这样的事情:

while there are rows in table:
write the number of rows as json and output files.

while there are rows being written as jsons and output files:
server is pinged for the number of jsons and output files.
如果
objects\u list.append(d)
在循环中,并且
fetchmany
更改为
fetchall
将返回所有记录,作为一个json对象,我希望遍历该表,并在下面的结构中将每个记录作为单个json发送到服务器。因此,当所有记录都作为json对象写入并随请求发送到服务器时,遍历表并打破循环

示例JSON
{
“元数据”:{},
“SRData”:{
“SRNumber”:“1-3580671”
}
}

我正在使用Pyodbc迭代我的表,并提取我想要发送到服务器的记录

我的脚本返回第一条记录,我希望在表中循环,并在where子句定义的特定时间范围内返回X个数量的记录

如何成功地将每一行作为单个JSON返回,并ping发送到的服务器

代码:

输出:

{
    "MetaData": {}, 
    "SRData": {
        "SRNumber": "1-3140751"
    }
}
{"status":{"code":311,"message":"Service Request Successfully updated","cause":""},"Response":{"PrimaryRowId":"1-1VBF3","ListOfServiceRequest":{"ServiceRequest":[{"SRNumber":"1-3140751"}]}}}

如果将
cursor.fetchmany()
更改为
cursor.fetchall()
,它是否有效?如果将
objects\u list.append(d)
放入for循环并设置

 output = {"MetaData": {}, "SRData": objects_list}

不,相同的输出,我认为它比这要复杂一点,似乎我需要一个while循环来输出,它将表中的每一行作为一个新的JSON对象进行迭代,并写入一个新的对象文件。如果将objects_list.append(d)放在for循环中会怎么样?不,我认为您认为我希望将表中的所有记录作为一个JSON返回,我想将表中的所有记录作为单个JSON返回。好吧,我想您应该将objects\u列表传递给输出。不过,您仍然需要将其放入for循环中。请参见编辑,我希望遍历整个表,并将每一行作为JSON发送到服务器,并在最后一条记录处中断循环。
 output = {"MetaData": {}, "SRData": objects_list}