[英]Obtain server error for Flask development server when deployed on Gcloud but works fine as local server due to permission
Error: sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) attempt to write a readonly database 2019-12-17 10:12:11 default[20191217t021035] [SQL: INSERT INTO post (title, date_posted, content, user_id) VALUES (?, ?, ?, ?)] 2019-12-17 10:12:11 default[20191217t021035] [parameters: ('hi', '2019-12-17 10:12:11.435775', 'hi', 3)] 2019-12-17 10:12:11 default[20191217t021035] (Background on this error at: http://sqlalche.me/e/e3q8 )错误:sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) 尝试写入只读数据库 2019-12-17 10:12:11 default[20191217t021035] [SQL: INSERT INTO post (title, date_posted, content, user_id) VALUES ?, ?, ?, ?)] 2019-12-17 10:12:11 default[20191217t021035] [参数:('hi', '2019-12-17 10:12:11.435775', 'hi', 3 ] 2019-12-17 10:12:11 default[20191217t021035](此错误的背景: http ://sqlalche.me/e/e3q8)
app.yaml应用程序.yaml
runtime: python37
env: standard
handlers:
- url: /main.css
static_dir: static/*
expiration: "1h"
runtime_config:
python_version: 3.7
# This configures Google App Engine to serve the files in the app's static
# directory.
#beta_settings:
# cloud_sql_instances: flask-journal:us-west1:flask-project1
entrypoint: gunicorn -b :$PORT run:app
config.py配置文件
import os
class Config:
SECRET_KEY = '[a correct key]'
SQLALCHEMY_DATABASE_URI = 'sqlite:///site.db'
# E-Mail with Flask
MAIL_SERVER = 'smtp.googlemail.com'
MAIL_PORT = 587
MAIL_USER_SSL = True
# Need to set environment variable
MAIL_USERNAME = os.environ.get('EMAIL_USER')
MAIL_PASSWORD = os.environ.get('EMAIL_PW')
MAIL_DEFAULT_SENDER = os.environ.get('EMAIL_USER')
Then I also have a site.db where the database is.然后我还有一个 site.db 数据库所在的位置。 After using
使用后
gcloud app deploy
The website hosted, but I am not able to engage in any operation that would change the database.该网站托管,但我无法进行任何会更改数据库的操作。 I am almost sure it is a permission error given the error output shown above.
鉴于上面显示的错误输出,我几乎可以肯定这是一个权限错误。 I saw solutions you can do chmod on Linux, but what do you do on Windows 10?
我看到了您可以在 Linux 上执行 chmod 的解决方案,但是您在 Windows 10 上做什么? I guess the "user" changing the database is now no longer permitted (even logged on) to write to the database when doing
我猜现在不再允许(甚至登录)更改数据库的“用户”在执行时写入数据库
db.commit()
The file system of the Google Cloud runtime is read-only ( https://cloud.google.com/appengine/docs/standard/python3/runtime#filesystem ): Google Cloud 运行时的文件系统是只读的 ( https://cloud.google.com/appengine/docs/standard/python3/runtime#filesystem ):
The runtime includes a full filesystem.
运行时包括一个完整的文件系统。 The filesystem is read-only except for the location
/tmp
, which is a virtual disk storing data in your App Engine instance's RAM.文件系统是只读的,但位置
/tmp
除外,它是一个虚拟磁盘,用于在 App Engine 实例的 RAM 中存储数据。
/tmp
(note four slashes in the SQLAlchemy DB URI for an absolute file path):/tmp
(注意 SQLAlchemy DB URI 中的四个斜杠表示绝对文件路径):SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/site.db'
SQLALCHEMY_DATABASE_URI = 'postgres://<db_user>:<db_pass>@/<db_name>?unix_sock=/cloudsql/<cloud_sql_instance_name>/.s.PGSQL.5432'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.