请求json身体

时间:2018-05-19 11:54:07

标签: python json python-3.x flask subprocess

我正在尝试创建一个简单的脚本来返回进程的状态。终点正在起作用,请求也是如此,错误如下:

AttributeError: 'str' object has no attribute 'get'

powershell.py:

import subprocess
import sys
import json
from flask import Flask, json


processDefender=subprocess.Popen(["powershell","get-process | Select-string lsass"], stdout=subprocess.PIPE, shell=False)
resultDef = processDefender.communicate()[0].decode('utf-8').strip()
dataPw = {}
dataPw['Defender'] = resultDef
dataFn = json.dumps(dataPw, sort_keys=True, indent=4)
print(dataFn)

run.py

import os
import json
import requests
import subprocess
from powershell import *
from DetectOS import *

r = requests.post('http://127.0.0.1:5000/connection', json=dataFn, headers={'Content-type': 'application/json', 'Accept': 'text/plain'})

API终点

@app.route('/connection', methods=['POST'])
def result():
    mydata = request.json # will be 
    print(mydata)
    return jsonify({'message' : '1!'})

0 个答案:

没有答案