Error FAQs 😢

Contributors: Alanna Zhou

  • No such file or directory: requirements.txt?

    • Check that you are currently where requirements.txt exists. You'll know this is the case if enter ls (MacOS) or dir (Windows) into your terminal and you don't see requirements.txt or if you didn't spell it right in your command.

    • Or, you may be trying to do pip3 install -r requirements.txt inside of a correctly created and activated venv, but your venv is nested within a path that contains a folder that has a space in the name. Here's a good Stack Overflow post that explains the issue.

  • No module named 'flask_sqlalchemy'?

    • Make sure you've run pip3 install -r requirements.txt in your activated virtual environment, check out the Virtual Environment page if you need more help!

  • ImportError: cannot import name 'Feature' from 'setuptools'?

    • Make sure that you have an updated Markupsafe version in your requirements.txt that you used to create virtual env: MarkupSafe==1.1.1

  • How to fix "KeyError: 'data'" from running test suite?

    • This means that your backend didn't respond with a format like:{ "success": True, "data": blah } so try making sure that your endpoints match the API spec linked in the backend course.

  • Postman keeps giving me an error?

    • Make sure you are hitting the correct URL in Postman. A correct URL looks like this: http://localhost:5000/api/posts/{id}/comments/, while some examples of incorrect ones look like this: http://localhost:5000/api/posts/{id}/comments, http://localhost:5000/posts/{id}/comments/

    • If you are making a POST request, make sure that you are submitting a JSON request. Body > Raw > JSON

  • Postman 404 Not Found?

    • Is your server running right now? Try checking your terminal. The server may stop when you make changes in your code has errors.

    • Also make sure that you have if name == "main": app.run(host="0.0.0.0", port=5000, debug=True) at the bottom of your app.py.

  • TypeError: list indices must be integers or slices, not str?

    • You may be returning a list, and accessing string values of that list (could be yourself or the testing script), instead of accessing string values of a dictionary. Make sure your responses abide by the API spec which indicates list/dictionary return types.

  • JSONDecodeError?!

    • JSONDecodeErrors are among the most common in this course. It's caused when the testing script tries to parse the JSON data associated with a response (variable res) that does not have any JSON data associated with it. This occurs when your code in app.py encounters an uncaught exception and crashes before your crafted responses can be returned. To debug a JSONDecodeError, you need to look at which request is breaking on res.json() and look deeper into that route method in app.py. We then recommend using Postman to test that specific route.

    • Double check that you are using double quotes " when creating a POST body request.

    • Instead of accessing key values of a dictionary like dict["key"], it's better to use dict.get("key") so that even if the POST request body doesn't contain the key, your code won't throw an error.

  • Test file's base_path = f"{LOCAL_URL}/api/user" has SyntaxError?

    • Our testing script uses what's called an f string. This is only supported by Python 3.6 or higher, so make sure you're running python3 test.py.

  • Table X has no column named Y?

    • Try using sqlite3 to help you debug in the terminal by

      1) opening sqlite3 shell: sqlite3

      2) loading your database file that you generate in your python code, which should show up in the same place as app.py: .open <YOUR FILENAME HERE>.db

      3) seeing all the tables in your database file .tables

      4) show what your table is made of (what the columns are): PRAGMA table_info(<YOUR TABLE NAME HERE>);

Last updated