[英]How the get the request data in python that was sent by a nodeJS server using Bottle
How to get and print the data that was sent by a nodeJS in python?如何在python中获取和打印nodeJS发送的数据?
I'm using ExpressJS in this nodeJs Module我在这个 nodeJs 模块中使用 ExpressJS
app.use("/py/sendomodel", function (req, res, next) {
var oData = {
"Test":"FirstData"
}
var options = {
method: 'POST',
data : oData,
url: 'https://xxx.cfapps.us10.hana.ondemand.com/mprs/omodel',
headers: {
'cache-control': 'no-cache',
/*'Content-Type' :'application/json',*/
Connection: 'keep-alive',
'accept-encoding': 'gzip, deflate',
Host: 'xxxx.cfapps.us10.hana.ondemand.com',
'Cache-Control': 'no-cache',
Accept: '*/*',
'User-Agent': 'PostmanRuntime/7.15.0'
}
};
return request(options, function (error, response,body,data) {
if (error) throw new Error(error);
});
});
Now I'm stuck here, how to print the data that was sent?现在我卡在这里,如何打印发送的数据? Here is the python Module这是python模块
from bottle import route, run, post, request, response
@route('/mprs/omodel', method='POST')
def profile():
#I tried all these without any success , I want to print the oData that I have sent via nodeJs
#request.body.read().decode('utf8')
temp = request.body.read()
#temp = request.json
#sol = request.forms
print(temp)
#jsonData = json.load(request.body)
#return jsonData
return(temp)
You have two separate things to look at, first is the query second your form data.您有两个单独的事情要查看,首先是查询,其次是表单数据。 I merge the two just in case.我将两者合并以防万一。 In your example, the body is empty.在您的示例中,主体是空的。 Since there is no actual HTML.因为没有实际的 HTML。
from bottle import route, run, post, request, response
def merge_dicts(*args):
result = {}
for dictionary in args:
result.update(dictionary)
return result
@post('/mprs/omodel')
def profile():
payload = merge_dicts(dict(request.forms), dict(request.query.decode()))
print(payload)
print(payload['Test'])
return payload
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.