0
votes

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.

  1. 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.
  2. 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()))

my CGI return message on browser

2
Did you try removing the line doc = None and do the check as described in "Get data" documentation? Let me know of the result. - tzovourn
Thank you for your comment. I tried try: except style instead of doc = None . But still my CGI shows Gateway Timeout. On the other hand, I can get data from server console. - OLTO and SUGI-cube Project
I find new way! My python can get firestore data if I call CGI from TOMCAT9! My problem is in my Apache. I will check my apache more! - OLTO and SUGI-cube Project
I update my httpd to Apache/2.4.43. Unfortunately still Apache CGI doesn't read data from firestore. What shall I do? - OLTO and SUGI-cube Project
I made golang app that get data from firestore. It read data if call from sercer screen. But from Apache CGI it can not get data. My Apache may have something wrong. - OLTO and SUGI-cube Project

2 Answers

0
votes

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

0
votes

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.