前言
碰到个升级的问题,原python3.6存在安全漏洞,升级处理后,早期部分代码无法运行。
问题1
ImportError: cannot import name 'parse_qs' from 'cgi'
处理1
Earlier Python versions allowed using both ; and & as query parameter separators in urllib.parse.parse_qs() and urllib.parse.parse_qsl(). Due to security concerns, and to conform with newer W3C recommendations, this has been changed to allow only a single separator key, with & as the default. This change also affects cgi.parse() and cgi.parse_multipart() as they use the affected functions internally. For more details, please see their respective documentation. (Contributed by Adam Goldschmidt, Senthil Kumaran and Ken Jin in bpo-42967.)
根据这个描述,cgi
中的parse_qs
用urllib.parse.parse_qs()
替代。
from urllib.parse import parse_qs
问题2
ImportError: cannot import name 'escape' from 'cgi'
处理2
使用html
进行替换
from html import escape
问题3
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:oracle
处理3
使用cx_freeze
对python代码打包后总是导致无法加载插件,到cx_frezz
脚本的构建选项中,在setup
参数build_exe
中的packages
中添加'sqlalchemy', 'pyodbc'
.
from cx_Freeze import setup, Executable
buildOptions = dict(excludes = [],
packages = ['sqlalchemy', 'pyodbc'] # 需要包含的两个包,其他按需添加
namespace_packages = []
)
setup(name='',
version = '0.1',
description = '',
options = dict(build_exe = buildOptions),
executables = executables)
参考
【1】cx_freeze 部署:sqlalchemy.exc.NoSuchModuleError:无法加载插件:sqlalchemy.dialects:mssql.pyodbc
【2】cgi — Common Gateway Interface support