I am using this tutorial
Background: I am using flask post API to activate selenium to extract information and send them to website. This work perfectly when I don't apply nginx configuration and just run the below code on server (as in local machine using port 5000).
Problem: when I try to deploy the flask application by mean of nginx and uwsgi and following the indication of this tutorial I get an internal server error whenever I do the POST request http://my_domain/find_data.
Below I'll show part of my code.
from app import app
if __name__ == "__main__":
app.run()
The app.py code (it manages the POST request http://my_domain/find_data) is:
from flask import Flask, send_from_directory, stream_with_context, request, Response
from flask_restful import Api, Resource, reqparse
from flask_cors import CORS #comment this on deployment
from data_finder import DataFinder
from time import sleep
from contextlib import closing
import requests
import json
from flask import jsonify
from flask import jsonify, make_response
app = Flask(__name__, static_url_path='', static_folder='frontend/build')
CORS(app) #comment this on deployment
api = Api(app)
@app.route("/")
def hello():
return send_from_directory(app.static_folder, 'index.html')
@app.route("/find_data", methods = ['POST'])
def FindData():
person = request.get_json()['person']
print(person)
results = {}
data_finder = DataFinder()
results['Spokeo'] = list(data_finder.get_spokeo_data(person))
results['White Pages'] = list(data_finder.get_whitepages_data(person).keys())
return make_response(jsonify(results), 200)
My project.ini file is this:
[uwsgi]
module = wsgi:app
master = true
processes = 5
socket = myproject.sock
chmod-socket = 660
vacuum = true
die-on-term = true
Lastly my nginx configuration file is
server {
listen 80;
server_name my_domain www.my_domain;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/help/data-finder/privaseame_web_app/myproject.sock;
uwsgi_read_timeout 900;
proxy_read_timeout 1800;
proxy_connect_timeout 1800;
proxy_send_timeout 1800;
send_timeout 1800;
}
client_header_timeout 900s;
client_body_timeout 900s;
keepalive_timeout 900s;
send_timeout 900s;
}
I am using digital ocean linux droplet Ubuntu 18-0.4 LTS Running python3.10.6 I used below stack overflow links but information on them is not sufficient
If I miss any information please let me know I will provide.
Thanks for your insight