python - 将 django 应用程序发布到 azure 时出现服务器错误

标签 python django azure django-pyodbc-azure

我正在尝试使用 MSSQL 服务器将我的 django 应用程序发布到 azure。我使用 django-azure-pyodbc 和 pyodbc 进行连接,虽然它在本地工作,但每当我使用 mssql 发布时,尽管发布成功,但我都会收到内部服务器错误。如果我使用预先打包的 sqllite3 服务器进行发布,它就可以工作。我使用的是 Python 3.4、Django 1.8.4、pyodbc 3.0.10 和 django-pyodbc-azure 1.8.3.0 的虚拟环境。我的settings.py文件如下。

DATABASES = {
   'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'db_name',
        'USER': 'u_name',
        'PASSWORD': 'p_word',
        'HOST': 'host.database.windows.net',
        'PORT': '',
    }
}

我已将 Web 应用程序的传出 IP 地址添加到服务器,希望这是问题所在,但事实并非如此。检查诊断日志后,我发现了比 500 错误更详细的解释,但我不确定我是否理解它。

 ModuleName FastCgiModule

 Data1 FASTCGI_RESPONSE_ERROR

Data2 Error occurred while reading WSGI handler: Traceback (most recent call last): File "D:\home\site\wwwroot\env\lib\site-packages\sql_server\pyodbc\base.py", line 14, in import pyodbc as Database ImportError: DLL load failed: %1 is not a valid Win32 application. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\Python34\Scripts\wfastcgi.py", line 711, in main env, handler = read_wsgi_handler(response.physical_path) File "D:\Python34\Scripts\wfastcgi.py", line 568, in read_wsgi_handler return env, get_wsgi_handler(handler_name) File "D:\Python34\Scripts\wfastcgi.py", line 541, in get_wsgi_handler handler = handler() File ".\ptvs_virtualenv_proxy.py", line 120, in get_venv_handler handler = get_wsgi_handler(os.getenv('WSGI_ALT_VIRTUALENV_HANDLER')) File ".\ptvs_virtualenv_proxy.py", line 78, in get_wsgi_handler handler = handler() File "D:\home\site\wwwroot\env\lib\site-packages\django\core\wsgi.py", line 14, in get_wsgi_application django.setup() File "D:\home\site\wwwroot\env\lib\site-packages\django__init__.py", line 18, in setup apps.populate(settings.INSTALLED_APPS) File "D:\home\site\wwwroot\env\lib\site-packages\django\apps\registry.py", line 108, in populate app_config.import_models(all_models) File "D:\home\site\wwwroot\env\lib\site-packages\django\apps\config.py", line 198, in import_models self.models_module = import_module(models_module_name) File "D:\Python34\lib\importlib__init__.py", line 109, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 2254, in _gcd_import File "", line 2237, in _find_and_load File "", line 2226, in _find_and_load_unlocked File "", line 1200, in _load_unlocked File "", line 1129, in _exec File "", line 1471, in exec_module File "", line 321, in _call_with_frames_removed File "D:\home\site\wwwroot\env\lib\site-packages\django\contrib\auth\models.py", line 41, in class Permission(models.Model): File "D:\home\site\wwwroot\env\lib\site-packages\django\db\models\base.py", line 139, in new new_class.add_to_class('_meta', Options(meta, **kwargs)) File "D:\home\site\wwwroot\env\lib\site-packages\django\db\models\base.py", line 324, in add_to_class value.contribute_to_class(cls, name) File "D:\home\site\wwwroot\env\lib\site-packages\django\db\models\options.py", line 250, in contribute_to_class self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) File "D:\home\site\wwwroot\env\lib\site-packages\django\db__init__.py", line 36, in getattr return getattr(connections[DEFAULT_DB_ALIAS], item) File "D:\home\site\wwwroot\env\lib\site-packages\django\db\utils.py", line 240, in getitem backend = load_backend(db['ENGINE']) File "D:\home\site\wwwroot\env\lib\site-packages\django\db\utils.py", line 111, in load_backend return import_module('%s.base' % backend_name) File "D:\Python34\lib\importlib__init__.py", line 109, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 2254, in _gcd_import File "", line 2237, in _find_and_load File "", line 2226, in _find_and_load_unlocked File "", line 1200, in _load_unlocked File "", line 1129, in _exec File "", line 1471, in exec_module File "", line 321, in _call_with_frames_removed File "D:\home\site\wwwroot\env\lib\site-packages\sql_server\pyodbc\base.py", line 16, in raise ImproperlyConfigured("Error loading pyodbc module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading pyodbc module: DLL load failed: %1 is not a valid Win32 application. StdOut: StdErr:

最佳答案

我真的不知道 Azure 是如何工作的,但在混合 32 位和 64 位驱动程序/python 组合时出现此错误。尝试使用 x64 位版本的 python 和驱动程序。

关于python - 将 django 应用程序发布到 azure 时出现服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33502166/

相关文章:

javascript - 将 JavaScript date() 转换为 Python Django models.DateTimeField

azure - 如何解压或获取存储在 Azure DevOps Build Piplines 变量组中的嵌套变量的值?

.net - 在 Powershell 脚本中将 Azure 信息保护添加到电子邮件

python - 使用opencv查找图像中的亮点

java - 生成用于 python 请求的证书获取 PEM lib 错误

python - JSON 使用被调用的值序列化 Django 查询集。我的方法有什么问题吗?

entity-framework - Code First Entity Framework 和 Windows Azure SQL

Python 脚本适用于 Mac 而不是 Ubuntu

python pandas - 根据包含字符串列表的 B 列更改 A 列中的值

保存后的 MySQL + Django : No obj. id()