如何解决我的CGI如何访问Firestore数据库?
我制作了python CGI以从Firestore获取数据。它可以很好地工作并从服务器获取数据,但是如果在浏览器上调用(URL:〜/ cgi-bin / xxxx)则不会。它仅显示504:Gateway Timeout错误。
- 如果我的CGI无法访问Forestore(注释掉代码),它将运行良好并在浏览器上显示消息。因此,我认为Apache设置很好。
- 我的python脚本可以获取服务器上的数据。因此,我认为Firebase的python设置很好。
但是我的CGI在浏览器上不起作用,为什么?
我检查了/ var / log / messages和/ var / log / httpd / ssl_error_log。我只能找到的消息是AH01220: Timeout waiting for output from CGI script
我检查了httpd.conf,没有发现错误。因此,如果cgi-bin / test.py无法访问firestore,则可以在浏览器上很好地运行。 /usr/firestore/database.json的权限为json 444,每个文件夹755。
我找不到路。有人和我一样有问题吗?
我的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>")
它在服务器上运行良好(执行./test.py),并显示这样的文档数据。
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>
如果这样注释掉“ doc = doc_ref.get()”,它将在浏览器上起作用。
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
解决方法
最后,我放弃了Apache。我有了新的Fire-base托管服务器和Node.js,而不是python。
新的Node.js运作良好。我对此感到满意。
另一方面,Tomcat运行良好。
我决定如下。
简单网页=> Fire-base托管(html)+ Node.js
复杂的Web应用=> Tomcat + JAVA
数据库=> fire-store
谢谢
,我明白了! 我将httpd从apache更改为nginx。 新的Nginx运作良好。我可以执行python CGI并连接火基数据库。 对我来说很方便。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。