Nginx returns 500 when NLTK is running with Java 18 in a Python Script

Viewed 17

I have a Python script with Flask API to read a text and identify some Person's Names. To do this, I'm using the NLTK library as follows. The library requires Java, and I installed Java 18 on the server. All the configurations are done and it is working when I run Python3 testFile.py But it gives 500 internal server error when I run the systemctl service through Nginx. All the rest of the APIs are working with Nginx and, even this API works without using NLTK in the Nginx. How can I solve this?

I checked the Nginx error log but this 500 error doesn't record in there.

testFile.py

import nltk
from nltk import tag

st = tag.stanford.StanfordNERTagger('stanford-ner/classifiers/english.all.3class.distsim.crf.ser.gz',
                                    'stanford-ner/stanford-ner.jar')

def isValidAddress(text):
    # nltk.download('punkt')

    tokens = nltk.word_tokenize(text)
    tags = st.tag(tokens)

    for item in tags:
        if item[1] == "PERSON":
            return True

    return False

/etc/nginx/sites-available/default

server {
        listen 80;
        listen [::]:80;
        location / {
            proxy_pass http://127.0.0.1:5000;
            proxy_set_header X-Real-IP $remote_addr;
        }
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    include snippets/self-signed.conf;
    include snippets/ssl-params.conf;
 location / {
            proxy_pass https://127.0.0.1:5000;
            proxy_set_header X-Real-IP $remote_addr;
        }
}

systemctl service

[Unit]
Description=Autoscale Flask project
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/root/smartcap-ai
ExecStart=/usr/bin/python3.6 /root/smartcap-ai/main.py
[Install]
WantedBy=multi-user.target
0 Answers
Related