I´m trying to create a simple script that will return the status of a process. The end point is working and the request too, the error is as below:
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 end point
@app.route('/connection', methods=['POST'])
def result():
mydata = request.json # will be
print(mydata)
return jsonify({'message' : '1!'})