Python将数据发布到Web服务

时间:2017-08-15 03:54:13

标签: python sql-server web-services post raspberry-pi

我正在尝试编写一个python脚本,将数据发布到连接到restful Web服务的Microsoft SQL Server数据库。但是,我收到一个我不理解的错误,之前从未遇到过。

发布数据的Python代码:

import json
import requests
import pprint
url = 'http://192.168.1.111/api/Data'
data = {'ID': '1', "ChannelID': '34','TimeStampID': '45'}
data_json = json.dumps(data)
headers = {'Content-type': 'application/json'}
response = requests.post(url, data=data_json, headers=headers)
pprint.pprint(response.json())

我得到的错误是: enter image description here

我还删除了名为json的所有文件,以防止错误的导入。上述错误是什么意思?我试着通过以下链接查找kwargs但是不明白。

Understanding kwargs in Python

*args and **kwargs?

非常感谢任何协助。

1 个答案:

答案 0 :(得分:0)

我不确定错误,但** args和** kwargs:

** args意味着您可以根据需要添加任意数量的参数

** kwargs是指Python中的关键字,不能用作变量名的关键字。见:

>>> import keyword
>>> print(keyword.kwlist)
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 
'del','elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 
'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 
'with', 'yield']