nutra Posted February 11, 2020 Posted February 11, 2020 Copied from the Discord chat. @KrydosI just got your message. I am using your .htaccess file as set forward in the wiki.<https://wiki.helionet.org/Flask>see: <http://nutra.heliohost.org/api> original message:nutra, AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error.You have a redirect loopProbably in your .htaccess file I have made only path modifcations renaming `/flask/` --> `/api/` RewriteEngine On RewriteBase / RewriteRule ^(media/.*)$ - [L] RewriteRule ^(admin_media/.*)$ - [L] RewriteRule ^(api\.wsgi/.*)$ - [L] RewriteRule ^(.*)$ api/flask.wsgi/$1 [QSA,PT,L]
Krydos Posted February 11, 2020 Posted February 11, 2020 RewriteRule ^(api\.wsgi/.*)$ - [L] RewriteRule ^(.*)$ api/flask.wsgi/$1 [QSA,PT,L] These two lines have to reference the same file name. In the top line you say the file is named api.wsgi, and in the second line you say it's flask.wsgi. Which one is it actually? The logic behind these two lines is the first one says "Is the request going through api.wsgi? If so stop processing rules and leave the request as is." The second line basically says, "If the request isn't going to flask.wsgi already redirect the request and process it through the .wsgi file." Since the two lines don't reference the same file name it just endlessly loops. 1
nutra Posted February 12, 2020 Author Posted February 12, 2020 I had replaced the public_html/flask folder with a /api one, had assumed it was flask folder not file. Apologies for any issues this cause on your end. But now I've updated it, and still have a generic 500. What would you recommend in this case, trying to log the error very early on, or? RewriteEngine On RewriteBase / RewriteRule ^(media/.*)$ - [L] RewriteRule ^(admin_media/.*)$ - [L] RewriteRule ^(flask\.wsgi/.*)$ - [L] RewriteRule ^(.*)$ api/flask.wsgi/$1 [QSA,PT,L] Thanks,nutra
Krydos Posted February 12, 2020 Posted February 12, 2020 [Wed Feb 12 04:01:47.630248 2020] [wsgi:error] [pid 10510] /usr/local/python3.7/lib/python3.7/site-packages/dotenv/main.py:52: UserWarning: File doesn't exist [Wed Feb 12 04:01:47.630302 2020] [wsgi:error] [pid 10510] warnings.warn("File doesn't exist {}".format(self.dotenv_path)) # type: ignore [Wed Feb 12 04:01:48.077793 2020] [wsgi:error] [pid 10510] [client 65.19.141.66:56883] mod_wsgi (pid=10510): Failed to exec Python script file '/home/nutra/public_html/api/flask.wsgi'. [Wed Feb 12 04:01:48.077974 2020] [wsgi:error] [pid 10510] [client 65.19.141.66:56883] mod_wsgi (pid=10510): Exception occurred processing WSGI script '/home/nutra/public_html/api/flask.wsgi'. [Wed Feb 12 04:01:48.120412 2020] [wsgi:error] [pid 10510] [client 65.19.141.66:56883] Traceback (most recent call last): [Wed Feb 12 04:01:48.120571 2020] [wsgi:error] [pid 10510] [client 65.19.141.66:56883] File "/home/nutra/public_html/api/flask.wsgi", line 7, in <module> [Wed Feb 12 04:01:48.120600 2020] [wsgi:error] [pid 10510] [client 65.19.141.66:56883] from server import app as application [Wed Feb 12 04:01:48.120628 2020] [wsgi:error] [pid 10510] [client 65.19.141.66:56883] File "/home/nutra/public_html/api/server.py", line 17, in <module> [Wed Feb 12 04:01:48.120645 2020] [wsgi:error] [pid 10510] [client 65.19.141.66:56883] from ntserv.accounts import ( [Wed Feb 12 04:01:48.120670 2020] [wsgi:error] [pid 10510] [client 65.19.141.66:56883] File "/home/nutra/public_html/api/ntserv/accounts.py", line 11, in <module> [Wed Feb 12 04:01:48.120687 2020] [wsgi:error] [pid 10510] [client 65.19.141.66:56883] from .postgres import psql [Wed Feb 12 04:01:48.120710 2020] [wsgi:error] [pid 10510] [client 65.19.141.66:56883] File "/home/nutra/public_html/api/ntserv/postgres.py", line 14, in <module> [Wed Feb 12 04:01:48.120727 2020] [wsgi:error] [pid 10510] [client 65.19.141.66:56883] options=f"-c search_path={PSQL_SCHEMA}", [Wed Feb 12 04:01:48.120752 2020] [wsgi:error] [pid 10510] [client 65.19.141.66:56883] File "/usr/local/python3.7/lib/python3.7/site-packages/psycopg2/__init__.py", line 126, in connect [Wed Feb 12 04:01:48.120769 2020] [wsgi:error] [pid 10510] [client 65.19.141.66:56883] conn = _connect(dsn, connection_factory=connection_factory, **kwasync) [Wed Feb 12 04:01:48.120843 2020] [wsgi:error] [pid 10510] [client 65.19.141.66:56883] psycopg2.OperationalError: FATAL: no pg_hba.conf entry for host "::1", user "root", database "nutra", SSL off You're trying to connect to postgres with the username root. That's never going to work. If you look at the first two lines, it looks to me like it's not finding your .env file.
Luigi123 Posted February 12, 2020 Posted February 12, 2020 Krydos has gave you the full list of the errors above. If you look at the first two lines, you’ll know what’s the issue.
nutra Posted February 12, 2020 Author Posted February 12, 2020 Yes, sorry. I made some changes I mean. The page took some time to load now, indicating something is happening but then it gave same 500. If theres a recommendation on how to pipe this error to a file, please share. After working on it the last two days, i also wonder to remove the .wsgi file and put that in the server.py file
Krydos Posted February 13, 2020 Posted February 13, 2020 Still the same error as yesterday, only now there is another write permission error on the log file: [Thu Feb 13 02:22:16.431547 2020] [wsgi:error] [pid 6287] /usr/local/python3.7/lib/python3.7/site-packages/dotenv/main.py:52: UserWarning: File doesn't exist [Thu Feb 13 02:22:16.431630 2020] [wsgi:error] [pid 6287] warnings.warn("File doesn't exist {}".format(self.dotenv_path)) # type: ignore [Thu Feb 13 02:22:16.656787 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] mod_wsgi (pid=6287): Failed to exec Python script file '/home/nutra/public_html/api/flask.wsgi'. [Thu Feb 13 02:22:16.656925 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] mod_wsgi (pid=6287): Exception occurred processing WSGI script '/home/nutra/public_html/api/flask.wsgi'. [Thu Feb 13 02:22:16.716822 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] Traceback (most recent call last): [Thu Feb 13 02:22:16.716987 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] File "/home/nutra/public_html/api/flask.wsgi", line 9, in <module> [Thu Feb 13 02:22:16.717013 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] from server import app [Thu Feb 13 02:22:16.717040 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] File "/home/nutra/public_html/api/server.py", line 17, in <module> [Thu Feb 13 02:22:16.717057 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] from ntserv.accounts import ( [Thu Feb 13 02:22:16.717082 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] File "/home/nutra/public_html/api/ntserv/accounts.py", line 11, in <module> [Thu Feb 13 02:22:16.717099 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] from .postgres import psql [Thu Feb 13 02:22:16.717122 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] File "/home/nutra/public_html/api/ntserv/postgres.py", line 14, in <module> [Thu Feb 13 02:22:16.717138 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] options=f"-c search_path={PSQL_SCHEMA}", [Thu Feb 13 02:22:16.717164 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] File "/usr/local/python3.7/lib/python3.7/site-packages/psycopg2/__init__.py", line 126, in connect [Thu Feb 13 02:22:16.717216 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] conn = _connect(dsn, connection_factory=connection_factory, **kwasync) [Thu Feb 13 02:22:16.717291 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] psycopg2.OperationalError: FATAL: no pg_hba.conf entry for host "::1", user "root", database "nutra", SSL off [Thu Feb 13 02:22:16.717314 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] [Thu Feb 13 02:22:16.717346 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] [Thu Feb 13 02:22:16.717363 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] During handling of the above exception, another exception occurred: [Thu Feb 13 02:22:16.717425 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] [Thu Feb 13 02:22:16.717464 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] Traceback (most recent call last): [Thu Feb 13 02:22:16.717523 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] File "/home/nutra/public_html/api/flask.wsgi", line 20, in <module> [Thu Feb 13 02:22:16.717544 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] with open('error.txt', 'w+') as f: [Thu Feb 13 02:22:16.717597 2020] [wsgi:error] [pid 6287] [client 65.19.141.66:62057] PermissionError: [Errno 13] Permission denied: 'error.txt'
nutra Posted February 13, 2020 Author Posted February 13, 2020 Ok so some such line as this was necessary early on in the .wsgi file, os.chdir("/home/nutra/public_html/api") However now I'm hitting a permissions error deep in the postgres driver Library code, I don't know if it's trying to write a log file or bind an HTTP port, but this is the new stacktrace: port: 20000 PermissionError(13, 'Permission denied') File "/home/nutra/public_html/api/flask.wsgi", line 21, in <module> host="127.0.0.1", port=port, debug=True, File "/usr/local/python3.7/lib/python3.7/site-packages/flask/app.py", line 990, in run run_simple(host, port, self, **options) File "/usr/local/python3.7/lib/python3.7/site-packages/werkzeug/serving.py", line 1008, in run_simple run_with_reloader(inner, extra_files, reloader_interval, reloader_type) File "/usr/local/python3.7/lib/python3.7/site-packages/werkzeug/_reloader.py", line 339, in run_with_reloader sys.exit(reloader.restart_with_reloader()) File "/usr/local/python3.7/lib/python3.7/site-packages/werkzeug/_reloader.py", line 183, in restart_with_reloader exit_code = subprocess.call(args, env=new_environ, close_fds=False) File "/usr/local/python3.7/lib/python3.7/subprocess.py", line 339, in call with Popen(*popenargs, **kwargs) as p: File "/usr/local/python3.7/lib/python3.7/subprocess.py", line 800, in __init__ restore_signals, start_new_session) File "/usr/local/python3.7/lib/python3.7/subprocess.py", line 1551, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename)
Krydos Posted February 13, 2020 Posted February 13, 2020 Binding to a port will be pointless because all inbound and outbound ports are either already in use by a process or blocked by the firewall. That's why flask and django run with wsgi so you can use port 80 and 443 and don't need to worry about proxying or anything like that.
nutra Posted February 16, 2020 Author Posted February 16, 2020 No port results in this error? OSError(98, 'Address already in use') File "/home/nutra/public_html/api/flask.wsgi", line 22, in <module> host="127.0.0.1", debug=True, File "/usr/local/python3.7/lib/python3.7/site-packages/flask/app.py", line 990, in run run_simple(host, port, self, **options) File "/usr/local/python3.7/lib/python3.7/site-packages/werkzeug/serving.py", line 988, in run_simple s.bind(server_address)
Recommended Posts