Error: read ECONNRESET , while running the python child process from nodejs

Kushan

I am getting the error while running python child process on EC2 Ubuntu from node js. The spawned child process is never invoked by node.js, however things are working perfectly fine on local. We initially were getting an EPIPE error, until we used 'sudo apt-get install libfontconfig' which then produced this error below:

events.js:160
      throw er; // Unhandled 'error' event
      ^ //error Error: read ECONNRESET
    at exports._errnoException (util.js:1020:11)
    at Pipe.onread (net.js:568:26)



        //child process             
        urlCrawlJob(hostname, pageCounter+1, accessToken); //recursive calling of the function


        var process = SPAWN('python', [PATH.join(__dirname,"../pyScripts/crawler.py")]),

        data = body.customers;
        dataString = '';

        console.log(`Spawned child pid: ${process.pid}`);
        process.stdout.on('error', function (err) {
            console.log('stdout error: ', err);
            console.log(err.code);
        });

        process.stdout.on('data', function(data){
            dataString+=data
            console.log(dataString);
        });
        process.stdout.on('end', function(){

            console.log("ending child process -----> call url");

        });
        process.stdin.write(JSON.stringify({"data":data,"hostname":hostname}));
        process.stdin.end();                

    //python script

## process_init.py

#crete seperate function, impletment oop concepet

import sys, json, pymongo, os


#defaukt address, email, phnNo, total spe

print "==> in crawler python"

#print sys.args[0];

def main():
    data = json.load(sys.stdin)
    hostname = data['hostname'];
    customerData = data['data'];

    print hostname


    collection = dbConnection(hostname)


    #isFile = open("/crawlerResult/"+hostname+".txt","w+")


    pwd = os.getcwd()

    print pwd
    file = open(pwd+"/crawlerResult/"+hostname+".txt", "a++")

    iteratingData(customerData, file, collection)


    print "=====\n\n"
    client.close();                             #close the db connection
    sys.stdout.flush();  

def dbConnection(hostname):

    #opening connection with db
    client = pymongo.MongoClient('127.0.0.1', 27017) ;                          # TODO: if connection already open do not open neew one
    #   print client
    db = client["customerLTV"];
    print db
    collection = db[hostname];
    return collection


def iteratingData(customerData, file, collection):

    count = 0
    data = {}
    for i in customerData:
        #print i
        count += 1
        #print len(i["addresses"]);

        try:


            strdata = {}
            strdata[count] = data   
            strdata = json.dumps(strdata)
            file.write(strdata + "\n")                  


            data.pop('_id', None)
            collection.insert(data)         
            data = {}
        except Exception, e:
            print str(e)

    print count;




#start process
if __name__ == '__main__':
    main()
Luca Lavorato

It looks like your modules are not installed correctly on the Ubuntu server. Did you install or update all the Ubuntu EC2 modules? Especially if the Python child processes are not running.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Nodejs Error: read ECONNRESET

RequestError: Error: read ECONNRESET nodejs

nodejs express webapp - ERROR: read ECONNRESET

How to stop the error 'read ECONNRESET' from happening

RequestError: Connection lost - read ECONNRESET while using SQL Server in nodejs

Read everything from child_process.spawn's stderr in nodejs

NODEJS - Websocket return Error: read ECONNRESET when refreshing browser

Async read console output with python while process is running

Retrieve bash error from NodeJS child_process.spawn

Run child processes as different user from a long running Python process

Error while running multiple Tensorflow sessions in the same Python process

read child process's output while it is alive

ECONNRESET error crashing NodeJS application

Run a process while other process is running python

Firebase Cloud Functions: Error: Unexpected error while acquiring application default credentials: read ECONNRESET

Potly on Nodejs - "socket hang up and read ECONNRESET"

RequestError: Connection lost - read ECONNRESET for mssql in nodejs

Getting error while running nodejs program

How to read errors from a child process?

Python script gives Syntax error while running it from Jenkins

reading a key from keyboard while the process is running

Cannot read STDOut from Process that is running in background

Run node as background process from script running as child process

How to break out from a shell while loop from a python child process?

Nodejs how to get child process from process Id

Do something while a process is running in python

Read console output of a running python process (script)

Error "Cannot read properties of undefined" while trying to pass data from child to parent component

Module build failed: Error: read ECONNRESET