首页 > 解决方案 > 在 apache2/windows 上以 wsgi 模式执行的 python3 烧瓶应用程序的问题

问题描述

我有一个烧瓶应用程序,可以在使用 python 3.8 以独立模式(main.py)启动时工作。当我在 apache2/windows 上以模式 wsgi (main.wsgi) 启动它时,应用程序启动但在 apache2 日志中出现此错误并崩溃:

from mysql.connector import *
AttributeError: module 'mysql.connector' has no attribute 'CMySQLConnection'

什么可以解释两个相同代码之间的这种行为差异?

我的 Apache2 虚拟主机:

define ROOT "C:/Data/st-2020/dev/python/cours-2020/v01-deployment/flask"
define SITE "impots"

 <VirtualHost *:80> 
    WSGIScriptAlias /app "${ROOT}/mainWithMySQL.wsgi"
    DocumentRoot "${ROOT}"
    ServerName ${SITE}
    ServerAlias *.${SITE}
    <Directory "${ROOT}">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

我的 Apache2 httpd.conf:

# python wsgi
LoadFile "c:/myprograms/python38/python38.dll"
LoadModule wsgi_module "c:/myprograms/python38/lib/site-packages/mod_wsgi/server/mod_wsgi.cp38-win_amd64.pyd"
WSGIPythonHome "c:/myprograms/python38"

标签: pythonwindowsmod-wsgimysql-connector

解决方案


问题是

from mysql.connector import *

我不得不将其重写为:

from mysql.connector import connect

我不知道为什么。


推荐阅读