I made python CGI to get data from firestore. It works well and get data from server but it doesn’t if call on browser (URL: ~/cgi-bin/xxxx). It shows 504:Gateway Timeout error only.
- If my CGI doesn’t access forestore (comment out code) it works well and show message on browser. So, I think Apache setting is good.
- My python script can get data on server. So, I think python setting for firebase is good.
But my CGI doesn’t work on browser, Why?
I checked /var/log/messages and /var/log/httpd/ssl_error_log. Only message I can find is AH01220: Timeout waiting for output from CGI script
I checked my httpd.conf and find no error. So cgi-bin/test.py can run well on browser if it doesn’t access firestore. Permissions on /usr/firestore/database.json are 444 for json and 755 for each folders.
I can not find the way. Anyone has problem same as me?
my CGI
#!/usr/bin/python
# -*- coding: utf-8 -*-
print("Content-Type: text/html;")
print("")
print("<!DOCTYPE html>")
print("<html lang='en'>")
print("<head>")
print(" <meta charset='utf-8'>")
print(" <title>hello world. from python</title>")
print("</head>")
print("<body>")
print(" <h1>hello world.</h1>")
# get firestore data
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
cred = credentials.Certificate("/usr/firestore/database.json")
firebase_admin.initialize_app(cred)
db = firestore.client()
# get "users" document
doc_ref = db.collection(u'users').document(u'test_doc')
doc = None
doc = doc_ref.get()
print(u'Get document data: ')
if doc is None:
print(u' doc is None')
else:
print(u' {}'.format(doc.to_dict()))
print("<p>This is test.py in cgi-bin.</p>")
print("</body>")
print("</html>")
It run well on server (execute ./test.py) and shows document data like this.
Content-Type: text/html;
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<title>hello world. from python</title>
</head>
<body>
<h1>hello world.</h1>
Get document data:
{'NAME': 'test doc', 'DESCRIPTION': 'ID is test_doc', 'ID': '3'}
<p>This is test.py in cgi-bin.</p>
</body>
</html>
It works on browser if comment out "doc = doc_ref.get()" like this.
doc = None
# doc = doc_ref.get()
print(u'Get document data: ')
if doc is None:
print(u' doc is None')
else:
print(u' {}'.format(doc.to_dict()))
2
Answers
Finally I gave up my Apache. I got new Fire-base hosting server and Node.js instead of python.
New Node.js works well. I'm satisfied with that. On the other hand Tomcat works well.
I decided my way as follows.
Simple web page => Fire-base hosting(html) + Node.js
Complex web app => Tomcat + JAVA
Database => fire-store
thank you
I got it!
I changed my httpd from apache to nginx.
New nginx works well. I can execute python CGI and connect fire-base DB.
It’s convenient for me.