简体   繁体   English

在 Gcloud 上部署时获取 Flask 开发服务器的服务器错误,但由于许可,作为本地服务器工作正常

[英]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 中存储数据。

  • So in theory you should be able to store the file inside /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'
  • But this means that a) the database will disappear every time your instance stops b) If you ever scale your application to more than one instance, each instance will have its own database.但这意味着 a) 每次实例停止时数据库都会消失 b) 如果您将应用程序扩展到多个实例,则每个实例都将拥有自己的数据库。
  • I suggest you have a look Postgresql on Google's Cloud SQL, see https://cloud.google.com/sql/docs/postgres/connect-app-engine for how to connect from app engine to a Google Cloud database server.我建议您在 Google 的 Cloud SQL 上查看 Postgresql,请参阅https://cloud.google.com/sql/docs/postgres/connect-app-engine了解如何从应用引擎连接到 Google Cloud 数据库服务器。 The config will then change to something like:然后配置将更改为:
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.

相关问题 “utf-8”编码在开发服务器上有效,但在部署时无效 - "utf-8" encoding works on development server but not when deployed 使用数据库连接将代码部署到Azure Web时,Flask应用程序无法呈现,但是在本地服务器上运行良好 - Flask app fails to render when deploying code to Azure Web with a database connection, but works fine from local server 列表在本地工作正常但在服务器中工作相反 - List in local working fine but in server works inverse 在服务器上部署时找不到文件,但在本地测试应用程序时工作正常 - File not found when deployed on server, but works fine when app is tested locally 在烧瓶开发服务器上使用 python flask 和 pexpect 工作失败,WSGI - Using python flask and pexpect works on flask development server fails with WSGI OperationalError at / no such table: 公共服务器上的 django_session 错误,站点在本地服务器上工作正常 - OperationalError at /no such table: django_session error on public server, site works fine on local server 使用Docker在gcloud上运行Flask的内部服务器错误 - Internal Server Error running Flask on gcloud using Docker Apache 在 gcloud 500 内部服务器错误上运行 Flask - Apache running Flask on gcloud 500 Internal Server Error Django Web App Code可在本地开发机上运行,​​但在部署到服务器时无法运行 - Django Web App Code works on local dev machine but not when deployed to server Flask 在本地工作,但不在服务器上? - Flask works locally, but not on a server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM