Every time i try to pull an item localhost:5000 gives me an internal server error
from flask import Flask, jsonify, request
from pymongo import MongoClient
import jsonapp = Flask(name)
with open(“backend/data/secret.json”) as fp:
secret = json.load(fp)
client = MongoClient(secret[“mongoURI”])db = client[“wow-ah-data”]
collection = db[“items”]
@app.route(“/items”, methods=[“GET”])
def get_items():
try:
item = collection.find({})
if item:
item[“_id”] = str(item[“_id”])
return jsonify(item), 200
else:
return jsonify({“message”: “No items found”}), 404
except Exception as e:
return jsonify({“message”: “An error occurred”, “error”: str(e)}), 500if name == “main“:
app.run(debug=True)`
Luke J is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1