我设法将所有东西连接起来。但是,我在服务器内部出现内部错误; /。该错误是由于使用而导致的]
函数中的[storage_client= storage.Client()
你好
#__init__.py code
from flask import Flask
from google.cloud import storage
app = Flask(__name__)
@app.route("/")
def hello():
#Does not work here
storage_client= storage.Client()
return "error"
#Works without @app.route("")
def test():
storage_client= storage.Client()
# successfuly connects and prints
print(storage_client)
if __name__ == "__main__":
app.run()
#wsgi code
#!/usr/bin/python
#!/usr/secret.json
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/html/FlaskApp/")
from google.cloud import storage
from FlaskApp import app as application
application.secret_key = 'Add your secret key'
当我连接到域时它说内部服务器错误
所以我拉起日志,似乎flaskapp.wsgi中存在错误,但我不太确定...
这里是var / apache2 / logs / logs.error中的日志
mod_wsgi (pid=23303): Target WSGI script '/var/www/html/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=23303): Exception occurred processing WSGI script '/var/www/html/FlaskApp/flaskapp.wsgi'.
Traceback (most recent call last):
File "/var/www/html/FlaskApp/flaskapp.wsgi", line 7, in <module>
from FlaskApp import app as application
File "/var/www/html/FlaskApp/FlaskApp/__init__.py", line 5, in <module>
storage_client = storage.Client()
File "/usr/local/lib/python2.7/dist-packages/google/cloud/storage/
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or ex$
您需要为计划使用的服务帐户提供凭据