DEV Community

Cover image for Talking to Python from JavaScript (and Back Again!)

Talking to Python from JavaScript (and Back Again!)

Andrew Healey on April 11, 2019

Something a lot of beginners struggle with is the concept of passing data between different programming languages. It's far more simple to understa...
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 • Edited

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

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

Collapse
 
ahmaddeel profile image
AhmadDeel

Great article. I have a question:

Is this way of talking between processes the same as overlapping?

I read an article that describes c++ and node overlapping so they can call each other's functions through compiled assembly. Here you just pass data through process streams.

Collapse
 
healeycodes profile image
Andrew Healey

The methods described in this article are different from what you're describing, which I believe is about C++/Node.js bindings. I haven't used C++ in-depth recently so that's all I can say. Hopefully, someone more knowledgable about this will chime in!

Collapse
 
juancarlospaco profile image
Juan Carlos

I think you are missing one of the best options, Nim lang.
Since it can compile to Python modules, JavaScript, NodeJS, WASM, C, C++, has DOM API, Frontend libs, Python like syntax, and uses literal JSON.

Collapse
 
jimmyferiawan profile image
jimmy feriawan

how about asynchronous in python and javascript ?