#๐ fastAPI 405 Method not found
20 messages ยท Page 1 of 1 (latest)
@regal basin
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
@app.get("/modules/{module_code}")
def getModuleDetail(module_code:str):
connection = get_connection()
cursor = connection.cursor()
try:
cursor.execute("SELECT * FROM courses WHERE course_code = ?",(module_code,)),
rows = cursor.fetchall()
return [dict(zip([col[0] for col in cursor.description], row)) for row in rows] # Convert rows to dicts
finally:
connection.close()
@app.post("modules/addcourse")
async def add_course(course: Course):
connection = get_connection()
cursor = connection.cursor()
try:
cursor.execute(
"INSERT INTO courses (course_code, module_name, credits, semester, is_elective) VALUES (?, ?, ?, ?, ?)",
(course.course_code, course.module_name, course.credits, course.semester, course.is_elective),
)
connection.commit()
return {"message": f"Course {course.module_name} added successfully"}
except sqlite3.IntegrityError:
raise HTTPException(status_code=400, detail="Course code already exists")
finally:
connection.close()
the get works, but the post doesnt
You are missing the / idk if that matters
"modules/addcourse" instead of "/modules/addcourse"
it works
i was ripping my hair out
one simple lil mistake
thanks
how often does thi happen to you
smple little mistakes like that?
every once in a while you just stare and look over it several times
the fact that i rewrote "addcourse" but didint check the rest
/close
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.