添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
I am trying to use an npm library that also needs to make some api calls, so I need to be able to make post requests from my javascript files. I am using python 3.4.3, django 1.6.6 and node.js 8.10.0. What I am trying to do is use subprocess.Popen in my routes to call some javascript methods and everything works fine until I make "callback-requests" to return a value from javascript back to python, because when I do, I get "BlockingIOError [Errno 11] write could not complete without blocking".

So I call js from python like this(I simplified the string):

p = subprocess.Popen("node -e 'require("script.js").doAsynchronousStuff(callbackRoute)'",
cwd=project_folder, shell=True, close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
retval = p.wait()

And my .js function looks about like this:

function doAsynchronousStuff(callbackRoute) {
    const data = ...;
    const params = {
        uri: callbackRoute,
        body: JSON.stringify(data),
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
    request(params, (error, response) => {
        console.log(error, response);
module.exports.doAsynchronousStuff = doAsynchronousStuff;

Some things I noticed is that I can always call the function from my bash console without issues and that it sometimes even works when I use my python routes, but most of the time it doesn't. If I was simply not allowed to make a request to django, while my subprocess is still running, then it should never work, right? This is the best way I could think of to use the library, but suggestions to different approaches are welcome.

Edit: Sorry, the preview in this editor doesn't look like the final version, I don't get it

[edit by admin: code formatting]

Sorry, we have had to rate-limit your feedback sending.
Please try again in a few moments... Thanks for the feedback! Our tireless devs will get back to you soon.