Skip to content

Load local file #5448

@Chance-Obondo

Description

@Chance-Obondo

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google "How to X in FastAPI" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

# THE ROOT API
# the data is a list of dictionaries
@app.get("/")
async def root():
    data = open('valid.json')
    json_data = json.load(data)

    return json_data[0]

Description

I am trying to load a local json file on my computer using my fast API main.py file. But I keep on getting a file not found error.
What could be the issue and how can I solve this problem considering I need to use the json content in the file within the app itself and not return it to an end user

Operating System

Windows

Operating System Details

Chrome OS

FastAPI Version

0.85.0

Python Version

3.8.12

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions