【发布时间】:2025-12-19 04:55:06
【问题描述】:
我是网络服务的新手,正在尝试使用 python 脚本发送以下基于 JSON 的请求:
http://myserver/emoncms2/api/post?apikey=xxxxxxxxxxxxx&json={power:290.4,temperature:19.4}
如果我将以上内容粘贴到浏览器中,它会按预期工作。但是,我正在努力从 Python 发送请求。以下是我正在尝试的:
import json
import urllib2
data = {'temperature':'24.3'}
data_json = json.dumps(data)
host = "http://myserver/emoncms2/api/post"
req = urllib2.Request(host, 'GET', data_json, {'content-type': 'application/json'})
response_stream = urllib2.urlopen(req)
json_response = response_stream.read()
如何将 apikey 数据添加到请求中?
谢谢!
【问题讨论】: