How do i fix Error 415 in Flask Python in this tiny code?

I am a beginner and i was trying to replicate a project from youtube tutorial but i got a strange message.

When i tryied to type curl http://localhost:5000/videos/video3 -d "title=New Video" -X PUT i got this error {"message": "Did not attempt to load JSON data because the request Content-Type was not 'application/json'."} I dont understood why the error is about JSON but you are problably more expert than me :)

There is the code:

from flask import Flask
from flask_restful import Resource, Api, reqparse

app = Flask("VideoApp")
api = Api(app)

parser = reqparse.RequestParser()
parser.add_argument("title", required=True)

videos = {
    "video1" : "First Video",
    "video2" : "Second Video"
    }

class Video(Resource):

    def get(self, video_id):
        if video_id == "all":
            return videos
        return videos[video_id], 201

    def put(self, video_id):
        args = parser.parse_args()
        new_video = {"title" : args["title"]}
        videos[video_id] = new_video
        return {video_id: videos[video_id]}, 201


api.add_resource(Video, "/videos/<video_id>")

if __name__ == "__main__":
    app.run()

Upvotes: 0

Views: 25

Answers (0)

Related Questions