Python ORM SQLAlchemy 的中文乱码问题解决
2016-03-07 12:58
1561 查看
Custom DBAPI connect() arguments
Custom arguments used when issuing theconnect()call to the underlyingDBAPI may be issued in three distinct ways. String-based arguments can bepassed directly from the URL string as query arguments:(第一种方式URL
query string:加上"?charset=utf8")
db = create_engine('postgresql://scott:tiger@localhost/test?argument1=foo&argument2=bar')
If SQLAlchemy’s database connector is aware of a particular query argument, itmay convert its type from string to its proper type.
create_engine()
also takes an argument
connect_argswhich is an additional dictionary that will be passed to
connect(). This can be used when arguments of a type other than string are required, and SQLAlchemy’s database connector has no type conversion logic present for that parameter:(第二种方式使用connect_arg参数方式)
db = create_engine('postgresql://scott:tiger@localhost/test', connect_args = {'argument1':17, 'argument2':'bar'})
The most customizable connection method of all is to pass a
creatorargument, which specifies a callable that returns a DBAPI connection:
def connect(): return psycopg.connect(user='scott', host='localhost') db = create_engine('postgresql://', creator=connect)
相关文章推荐
- 用键盘控制鼠标移动的Python脚本
- 用 python 实现一个多线程网页下载器
- 简明 Python 编程规范v2
- Python 字符串方法详解
- Python温故
- Python的zip函数
- python学习随笔--web框架
- 源码:自己用Python写的iOS项目自动打包脚本
- 输入 pydoc print 提示 SyntaxError: invalid syntax
- Programming Language :: Python :: Understanding Twisted Deferred
- 关于opencv3.1编译的时候找不到python的lib的解决方法
- python学习之模块:xlsxwriter
- python urlopen SSL: CERTIFICATE_VERIFY_FAILED
- python中try except处理程序异常的三种常用方法
- Python ROM SQLAlchemy Document
- Python如何进行中文注释
- 机器学习算法 Python & R速查表
- 【python】编程语言入门经典100例--22
- Python基础(Django)
- python启动程序