我正在尝试从webapp获取json数据:
我试过了:
pytz
然后:
from flask import Flask
from flask import request
app = Flask(__name__)
@app.route('/postjson', methods = ['POST'])
def postJsonHandler():
print (request.is_json)
content = request.get_json()
print (content)
return 'JSON posted'
app.run(port= 8090)
我正在接受:
在服务器端:
import requests
url='http://127.0.0.1:8090/postjson'
hj=requests.post(url,{
"device":"TemperatureSensor",
"value":"20",
"timestamp":"25/01/2017 10:10:05"
})
print(hj.text)
和客户输出:
* Running on http://127.0.0.1:8090/ (Press CTRL+C to quit)
127.0.0.1 - - [22/Apr/2018 01:45:54] "POST /postjson/ HTTP/1.1" 404 -
127.0.0.1 - - [22/Apr/2018 01:46:01] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [22/Apr/2018 01:46:01] "GET /robots.txt HTTP/1.1" 404 -
127.0.0.1 - - [22/Apr/2018 01:51:46] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [22/Apr/2018 01:51:47] "GET /robots.txt HTTP/1.1" 404 -
127.0.0.1 - - [22/Apr/2018 01:52:26] "GET /postjson' HTTP/1.1" 404 -
127.0.0.1 - - [22/Apr/2018 01:52:48] "GET /postjson/ HTTP/1.1" 404 -
我只想发布json并接收并将其保存到服务器端的变量
答案 0 :(得分:0)
发布脚本时只有一个问题。您需要在hj=requests.post(url,json='some json')
电话中设置参数,即requests.post
它也可以从def post(url, data=None, json=None, **kwargs):
函数定义import requests
url='http://127.0.0.1:8090/postjson'
hj=requests.post(url,json = {
"device":"TemperatureSensor",
"value":"20",
"timestamp":"25/01/2017 10:10:05"
})
print(hj.text)
中看出来,所以在你的情况下,你把它作为数据而不是json发送。
textPaint.getTextBounds(text, 0, text.length(), bounds);