1. use database

2. use redis

3. inport/export excel2007 version+  

from flask import send_from_directory
import openpyxl
# not xlwt or xlrd

4. how to debug

5. how to deploy

6. pylint rules 参见

http://pylint-messages.wikidot.com/messages:c0111

7. create a virtualenv

$ virtualenv venv
$ source bin/activate
venv]$ pip install -r requirements.txt
venv]$ deactivate

8. flask-sqlalchemy paginate

from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://user:password@host:port/database?charset=utf8mp4'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db_session = SQLAlchemy(app).session obj = db_session.quert(MODEL).filter(...).paginate(page=2, per_page=10)
obj.total
obj.pages
obj.items

问题1:

ORM使用原生SQLAlchemy时报错。

官网参考地址 http://docs.sqlalchemy.org/en/latest/dialects/mysql.html#connection-timeouts

使用姿势如下:

from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker def create_app(conf_name=None):
app = Flask(__name__)
......
db_session = scoped_session(sessionmaker(
autocommit=False, autoflush=False,
bind=create_engine('mysql+pymysql://{USER}:{PASSWORD}@{HOST}:{PORT}/{DATABASE}?charset=utf8mb4',
convert_unicode=True)))

报错如下:

OperationalError: (pymysql.err.OperationalError) (2006, "MySQL server has gone away (error(32, 'Broken pipe'))")

or

OperationalError: (pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server during query')

解决办法如下:

阅读源码 ./python2.7/site-packages/sqlalchemy/engine/__init__.py 发现

    :param pool_recycle=-1: this setting causes the pool to recycle
connections after the given number of seconds has passed. It
defaults to -1, or no timeout. For example, setting to 3600
means connections will be recycled after one hour. Note that
MySQL in particular will disconnect automatically if no
activity is detected on a connection for eight hours (although
this is configurable with the MySQLDB connection itself and the
server configuration as well).

查看MySQL timeout 配置为默认值8小时

mysql> show variables like '%timeout%';
+-----------------------------+----------+
| Variable_name | Value |
+-----------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| have_statement_timeout | YES |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 3600 |
| thread_pool_idle_timeout | 60 |
| wait_timeout | 28800 |
+-----------------------------+----------+
14 rows in set (0.00 sec)

所以在create_engine时新增参数 pool_recycle=3600。

至此 问题修复。

how to create a flask server的更多相关文章

  1. Create a SQL Server Database on a network shared drive

    (原文地址:http://blogs.msdn.com/b/varund/archive/2010/09/02/create-a-sql-server-database-on-a-network-sh ...

  2. How to create a PPPoE Server on Ubuntu? (Untested)

    How to create a PPPoE Server on Ubuntu? March 30, 2011 coder_commenter Leave a comment Go to comment ...

  3. [转]How to: Create a Report Server Database (Reporting Services Configuration)

    本文转自:https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms157300%28v%3dsql.10 ...

  4. 报错:Cannot create PoolableConnectionFactory (The server time zone value 'CST' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverT

    报错:Cannot create PoolableConnectionFactory (The server time zone value 'CST' is unrecognized or repr ...

  5. How to create a jump server in AWS VPC

    本来是写的Word文档,给其他国家的同时看的,所以一开始就是英文写的,也没打算翻译成为中文了,顺便抱怨下,网上资料找了很久的资料都没有看到介绍怎么在单机环境下搭建RD Gateway的,写本文的目的是 ...

  6. (转)Genymotion安装virtual device的“unable to create virtual device, Server returned Http status code 0”的解决方法

    网络原因无法下载virtual device,status 为0表示服务器没有响应.FQ下载吧,有VPN的小伙伴推荐这种. 或者直接手动下载ova虚拟机文件,然后将虚拟机文件导入到virtualbox ...

  7. Genymotion加入模拟器时报“Unable to create virtual device,Server returned HTTP status code 0”

    今天也遇到这个问题,算是对这个文章的一点补充 打开图中这个文件 C:\Users\xxx\AppData\Local\Genymobile 搜索 [downloadFile] 找到这个一串URL ht ...

  8. Error generating Swagger server (Python Flask) from Swagger editor

    1down votefavorite   http://stackoverflow.com/questions/36416679/error-generating-swagger-server-pyt ...

  9. Create Windows Server 2008 cluster from the command line

    How to create a Windows Server 2008 cluster from the command line? Creating a cluster in Server 2008 ...

随机推荐

  1. sqli-labs(46)

    0X01首先我们先来看一下源码 发现查询语句变成了 order by  参数也变成了 sort 看看是什么样的 ()首先看看本关sql语句 $sql = "SELECT * FROM use ...

  2. C++入门经典-例6.7-字符串比较

    1:strcmp函数,用于比较两个字符串.格式如下: strcmp(字符数组名1,字符数组名2) 按照ASCII码,按顺序比较两个数组中的字符,并由函数返回值返回比较结果的执行过程. (1)各自选中自 ...

  3. C++入门经典-例6.1-一维数组元素

    1:代码如下: // 6.1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> using ...

  4. 二、Smarty中的三种主要变量

    1.从PHP中分配的变量 $smarty -> assign(); 从PHP分配给模板使用的变量:动态变量 2.从配置文件中读取的变量 $smarty配置文件中的内容不是PHP读取,而是就在sm ...

  5. 【攻克RabbitMQ】常见问题

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/zlt995768025/article/ ...

  6. legend3---lavarel常用操作代码

    legend3---lavarel常用操作代码 一.总结 一句话总结: 要自己总结一下常用代码,这样才方便,也才有收获 1.路由示例:Route::get('/login','Home\Login\L ...

  7. 后盾网lavarel视频项目---Laravel 安装代码智能提示扩展「laravel-ide-helper」

    后盾网lavarel视频项目---Laravel 安装代码智能提示扩展「laravel-ide-helper」 一.总结 一句话总结: laravel-ide-helper作用是:代码提示 larav ...

  8. Uva 101 -- the block problem

    Uva 101 the block problem 题目大意: 输入n,得到编号为0~n-1的木块,分别摆放在顺序排列编号为0~n-1的位置.现对这些木块进行操作,操作分为四种. 1.move a o ...

  9. 解决:linux eclipse 对‘dlopen’未定义的引用, 对‘xxx’未定义的引用

    如果是终端窗口执行的话直接: 在g++编译选项后面,加入dl的库,选项为-ldl,即可. 如果是在eclipse里的话: 在工程属性中->c/c++ build->gcc complier ...

  10. Navicat1_介绍

    https://study.163.com/course/courseMain.htm?courseId=1006383008&share=2&shareId=400000000398 ...