FastApi docs. Terminal output integration #8649
-
First Check
Commit to Help
Example Code@app.get("/azure")
def az_cli (args_str):
temp = tempfile.TemporaryFile()
args = args_str.split()
code = get_default_cli().invoke(['login', '--service-principal', '-u', '', '-p', '','--tenant',''])
resource = get_default_cli().invoke(args)
data = temp.read().strip()
temp.close()
return [args, resource]Descriptionsorry for this basic question but I would like some help from you expert as I am still learning fastaapi. I have a simple testing application running python FastApi and trying to use it with azure cli. what I am trying to do, is to have a get request using fastapi to list all the resource groups I have in my subscriptions. The Above code works just fine, I am able to run it as expected, but the output is visible in my terminal only, in I know this question might sound very basic but I really don't know exactly where to look and how to add the terminal output to my response body. Thank you very much for any help you can provide me with and I am sorry for the basic question Operating SystemmacOS Operating System DetailsNo response FastAPI Version0.68.1 Python Version3.9.6 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Its not related to FastAPI. But I found a solution for you here. |
Beta Was this translation helpful? Give feedback.
-
|
@ElAouaneHamza With you example, it's a bit difficult to understand what the data is that you want to return from the function. I would recommend that you look at building a JSONResponse where you can craft the exact data that you want to return: https://fastapi.tiangolo.com/advanced/response-directly/#using-the-jsonable_encoder-in-a-response The alternative is to create a pydantic model object and rather than return a list, you should return a pydantic object. A good example on returning a pydantic object can be found here: https://fastapi.tiangolo.com/tutorial/response-model/ |
Beta Was this translation helpful? Give feedback.
Its not related to FastAPI. But I found a solution for you here.