NodeJS, SocketIO, Python – Problem with calling a function

I have a nodeJS script, which calls a py script:

const { spawn } = require('child_process');

const callPythonFunctionRequest = async (functionName, argument1, argument2) => {
return new Promise((resolve, reject) => {
const pythonProcess = spawn('py', ['pathgetNmatch.py', functionName, argument1, argument2]);

pythonProcess.stdout.on('data', (data) => {
  console.log(`stdout: ${data}`);
});

pythonProcess.stderr.on('data', (data) => {
  console.log(`stderr: ${data}`);
  reject(new Error(`Error running Python script: ${data}`));
});

pythonProcess.on('exit', (code, data) => {
  console.log(`Python script exited with code ${code}`);
  if (code === 0) {
    resolve();
  } else {
    reject(new Error(`Python script exited with code ${code}`));
  }
});

pythonProcess.on('error', (err) => {
  console.log(`Error spawning Python process: ${err}`);
  reject(err);
});

pythonProcess.on('close', (code) => {
  console.log(`Python script closed with code ${code}`);
});
});
};

exports.callPythonFunctionRequest = callPythonFunctionRequest;

as arguments i give a filenames of files, that it need to compare

import cv2
import base64
import numpy as np
import json

def decode(b64string):
decoded_data = base64.b64decode(b64string)
np_data = np.frombuffer(decoded_data, np.uint8)
img = cv2.imdecode(np_data, cv2.IMREAD_COLOR)
return img

def match(content_sample, content_sql, id, arr_keys, req_id):
sift = cv2.SIFT_create()
decoded_sample = decode(content_sample)
bf = cv2.BFMatcher()
best_score = 0
best_decoded_sql = None
kp1, kp2, mp = None, None, None
result = None
for element in content_sql:
    for key in arr_keys:
        decoded_sql = decode(element[f'{key}'])
        decoded_sample = cv2.resize(decoded_sample, (decoded_sql.shape[1], 
decoded_sql.shape[0]))
        # cv2.imshow('1', decoded_sample)
        # cv2.imshow('2', decoded_sql)
        # cv2.waitKey(0)
        # cv2.destroyAllWindows()
        keypoints_1, descriptors_1 = sift.detectAndCompute(decoded_sample, None)
        keypoints_2, descriptors_2 = sift.detectAndCompute(decoded_sql, None)

        matches = bf.knnMatch(descriptors_1, descriptors_2, k=2)

        match_points = []

        for p, q in matches:
            if p.distance < 0.1 * q.distance:
                match_points.append(p)

        keypoints = min(len(keypoints_1), len(keypoints_2))
        if len(match_points) / keypoints * 100 > best_score:
            best_score = len(match_points) / keypoints * 100
            kp1, kp2, mp = keypoints_1, keypoints_2, match_points
            best_decoded_sql = decoded_sql
            best_key = key
            result = cv2.drawMatches(decoded_sample, kp1, best_decoded_sql, kp2, mp, 
None)
    _, img_encoded = cv2.imencode('.png', result)
    base64_string = base64.b64encode(img_encoded)
    matched_data = {'res_score': best_score, 'res_key': best_key, 'res_id': id}
    return matched_data

def createFile(data, id):
with open(f"path\result_req_{id}.json", "w") as outfile:
    json.dump(data, outfile)

def divide(sample, giant_arr):
print('called py fu')
req_id = sample.split("_")
req_id = sample.split(".")
arr_keys = []
with open(f'path\request\{sample}', 'r') as file:
    sample = file.read()
with open(f'path\request\{giant_arr}', 'r') as file:
    content_sql = json.load(file)
    for content in content_sql:
        id = content['id']
        for item in content:
            if item != 'id':
                arr_keys.append(item)
result = match(sample, content_sql, id, arr_keys, req_id[0])
createFile(result, req_id)
print(result)
return result

and this code must create a json file with the result, but it not happens, what’s the problem and how to solve it?

i call a callPythonFunctionRequest this way:

await callTestPyFunc(file_name_req, file_name_db)

I just don’t know what I can do, I’ve tested a huge number of options including AI hints to solve this problem but it doesn’t work…

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật