@Singletoned的示例不适用于SQLAlchemy 0.7.2。从用于连接到SQL
Server的SQLAlchemy文档中:
If you require a connection string that is outside the options presentedabove, use the odbc_connect keyword to pass in a urlenpred connection string.What gets passed in will be urldepred and passed directly.
因此,为了使它起作用,我使用了:
import urllibquoted = urllib.quote_plus('DRIVER={FreeTDS};Server=my.db.server;Database=mydb;UID=myuser;PWD=mypwd;TDS_Version=8.0;Port=1433;')sqlalchemy.create_engine('mssql+pyodbc:///?odbc_connect={}'.format(quoted))
这也应适用于Sybase。
注意:在python 3中,urllib模块已拆分为多个部分并重命名。因此,python 2.7中的这一行:
quoted = urllib.quote_plus
必须在python3中更改为这一行:
quoted = urllib.parse.quote_plus