DEV Community

loading...

Discussion on: Talking to Python from JavaScript (and Back Again!)

Collapse
avainlakech profile image
avainlakech

Thank you for this tutorial Andrew. In your use of the fetch library, I believe that in order to send valid JSON you need to add the following to the JSON payload section.

    headers:{
        'Content-Type': 'application/json'
    }

See here: developer.mozilla.org/en-US/docs/W...

Collapse
healeycodes profile image
Andrew Healey Author

You're correct, this is the best way to do it as it's more explicit, and certain web servers will require the header. I'd love to know what header it uses by default as my examples worked and I wanted to cut down on code so I removed it. I assumed that by default it was actually using 'application/json'. Hm 😊

Collapse
avainlakech profile image
avainlakech

For me when I sent the payload to the flask/python side it was interpreted as nonetype.

Thread Thread
healeycodes profile image
Andrew Healey Author

Ah, well there's our answer. Great. Thanks for letting me know! I'll update this post later 👍