为什么 Apache 服务器在 python 中使用雪花摄取模块抛出语法错误

Why Apache server throws syntax error with snowflake ingest module in python

我在 Linux 框(ec2 实例)中的 apache 服务器上有一个 Flask 应用程序 运行,它调用 python 脚本来完成从 s3 移动文件的工作雪花。如果直接执行,该脚本可以正常工作。当尝试使用 virtualhost 和 mod_wsgi 在 apache 上托管它时,它会为雪花的摄取 python 模块抛出以下错误。该模块安装在默认站点包中。

Apache 服务器版本:2.4.41

Python版本:3.7

雪花:snowflake_connector_python-2.1.3-py3.7-nspkg.pth

OS:亚马逊 linux 2

以下是 apache 错误日志,当我尝试重新启动时:

[Fri Jan 10 15:47:53.703083 2020] [:error] [pid 19755] [remote 67.79.202.36:20] mod_wsgi (pid=19755): 目标 WSGI 脚本 '/var/www/FLASKAPPS/snowflakeingestapp/snowflakeingestapp.wsgi' 无法加载为 Python 模块。

[Fri Jan 10 15:47:53.703113 2020] [:error] [pid 19755] [remote 67.79.202.36:20] mod_wsgi (pid=19755): 处理 WSGI 脚本时发生异常'/var/www/FLASKAPPS/snowflakeingestapp/snowflakeingestapp.wsgi'.

[Fri Jan 10 15:47:53.703129 2020] [:error] [pid 19755] [remote 67.79.202.36:20] Traceback(最近调用最后):

[Fri Jan 10 15:47:53.703142 2020] [:error] [pid 19755] [remote 67.79.202.36:20] 文件“/var/www/FLASKAPPS/snowflakeingestapp/snowflakeingestapp.wsgi”,第 4 行,在

[Fri Jan 10 15:47:53.703176 2020] [:error] [pid 19755] [remote 67.79.202.36:20] from snowflakeingestapp import app as application

[1 月 10 日星期五 15:47:53.703181 2020] [:error] [pid 19755] [远程 67.79.202.36:20] 文件“/var/www/FLASKAPPS/snowflakeingestapp/init.py",第 6 行,在

[1 月 10 日星期五 15:47:53.703206 2020] [:error] [pid 19755] [远程 67.79.202.36:20] 导入 snowflake_ingest

[1 月 10 日星期五 15:47:53.703210 2020] [:error] [pid 19755] [远程 67.79.202.36:20] 文件“/var/www/FLASKAPPS/snowflakeingestapp/snowflake_ingest/init.py", 第 1 行,在

[1 月 10 日星期五 15:47:53.703225 2020] [:error] [pid 19755] [远程 67.79.202.36:20] 导入 ingest_ecomm_json_snowpipe

[1 月 10 日星期五 15:47:53.703230 2020] [:error] [pid 19755] [远程 67.79.202.36:20] 文件“/var/www/FLASKAPPS/snowflakeingestapp/snowflake_ingest/ingest_ecomm_json_snowpipe.py",第 20 行,在

[Fri Jan 10 15:47:53.703296 2020] [:error] [pid 19755] [remote 67.79.202.36:20] from snowflake.ingest import SimpleIngestManager

[1 月 10 日星期五 15:47:53.703300 2020] [:error] [pid 19755] [远程 67.79.202.36:20] 文件“/usr/local/lib/python3.7/site-packages/snowflake/ingest/ init.py", 第 1 行,

[Fri Jan 10 15:47:53.703315 2020] [:error] [pid 19755] [remote 67.79.202.36:20] from .simple_ingest_manager import SimpleIngestManager, StagedFile

[1 月 10 日星期五 15:47:53.703342 2020] [:error] [pid 19755] [远程 67.79.202.36:20] 文件“/usr/local/lib/python3.7/ site-packages/snowflake/ingest/simple_ingest_manager.py”,第 65 行

[Fri Jan 10 15:47:53.703345 2020] [:error] [pid 19755] [remote 67.79.202.36:20] def init(self, account :文本,用户:文本,管道:文本,private_key:文本,

[1 月 10 日星期五 15:47:53.703347 2020] [:error] [pid 19755] [远程 67.79.202.36:20] ^

[Fri Jan 10 15:47:53.703350 2020] [:error] [pid 19755] [remote 67.79.202.36:20] SyntaxError: invalid syntax

看起来当您从 mod_wsgi 执行此操作时,您使用的是 Python 2 而不是 Python 3。您看到的错误消息是因为 Snowflake 的简单摄取管理器使用类型提示(通过 typing 模块),这在 Python 2.

中不可用

这是一个简单的片段,它在 Python 2 中失败并出现相同的错误,但在 Python 3 中成功:

from typing import Text
def foo(bar: Text):
    print(bar)
foo('huh')