Communicate between Python and Node.js

Manish gill.manish90 at gmail.com
Wed Jan 15 12:12:16 EST 2014


I've been tasked to write a module that sends data from Django to a Node.js server running on the same machine. Some magic happens in node and I recv the results back, which are then rendered using Django templates. 

At first I thought to use the requests library to GET/POST data to node, but I googled around and it seems lots of people think TCP sockets are the way to go. I tried implementing my own using several examples I have found online. It *kind of* works. It seems like I get blocked while trying to receive data back in the recv() loop. I never reach the end. I'm not an expert in sockets/networking, but maybe I'm not wrong in guessing it is because of the non-blocking nature of Node.js ?

A Stackoverflow post helped a little more in figuring things out (though I'm not sure if I'm correct here). Right now, I'm failing during connect() - I get "Operation now in progress". 

So my question is, how can I get recv() to work properly so that data is seamlessly passed back and forth between my Python script and the node server. Am I taking the right approach? Is there any better way? 

Relevant scripts: 
    1) http://bpaste.net/show/NI2z9RhbT3HVtLVWUKuq/ 
    2) http://bpaste.net/show/YlulEZBTDE5KS5ZvSyET/

Thanks! 




More information about the Python-list mailing list