【发布时间】:2019-10-10 13:50:09
【问题描述】:
我正在尝试运行一个 php 脚本,该脚本将调用一个 python 脚本,该脚本调用 imaplib 从我的电子邮件中提取一些文件。当我在 vscode(bash 终端)中独立运行 python 脚本时,它按设计工作。当我运行调用python脚本的PHP脚本时,会产生以下错误。
Traceback (most recent call last):
File "C:/xampp/htdocs/report/pythonfile/parse_script_og.py", line 43, in <module>
mail = imaplib.IMAP4_SSL('imap.googlemail.com')
AttributeError: module 'imaplib' has no attribute 'IMAP4_SSL'
作为测试,我回显了命令并将其粘贴到 Git Bash 中。文件被拉出并添加到指定的文件夹中。当我将命令粘贴到 CMD 中时,产生了上述错误。我缺少什么设置?
我正在使用 XAMPP、VSCode、PHP 7.3.4、Python 3.7.1
根据下面的推荐,我在我的 python 脚本中添加了“import ssl”,我收到以下错误:
"Traceback (most recent call last):"
" File "C:/xampp/htdocs/report/pythonfile/parse_script_og.py", line 2, in <module>"
" import ssl"
" File "C:\Users\Garrett\Anaconda3\envs\snowflakes\lib\ssl.py", line 98, in <module>"
" import _ssl # if we can't import it, let the error propagate"
"ImportError: DLL load failed: The specified module could not be found."
然后我去了我的python环境,并尝试“pip install ssl”,我得到了以下错误。
(snowflakes) C:\Users\Garrett>pip install ssl
Collecting ssl
Using cached https://files.pythonhosted.org/packages/83/21/f469c9923235f8c36d5fd5334ed11e2681abad7e0032c5aba964dcaf9bbb/ssl-1.16.tar.gz
ERROR: Complete output from command python setup.py egg_info:
ERROR: Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Garrett\AppData\Local\Temp\pip-install-abzxmk8x\ssl\setup.py", line 33
print 'looking for', f
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('looking for', f)?
----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in C:\Users\Garrett\AppData\Local\Temp\pip-install-abzxmk8x\ssl\
(snowflakes) C:\Users\Garrett>
另一个更新
以下命令是在 PHP (exec()) 中执行的。输入文件夹将包含从电子邮件中提取的文件。输出文件夹将包含一个从电子邮件中提取的文件创建的单一文件。如果我将此命令粘贴到 GitBash 中,一切都会按计划进行。如果我将以下命令粘贴到 CMD 中,则会收到上面显示的错误。
C:/Users/Garrett/Anaconda3/python.exe C:/xampp/htdocs/report/pythonfile/parse_script_og.py C:/xampp/htdocs/report/input/ C:/xampp/htdocs/report/output/out.csv John Doe 06-Jan-2018 16-Jan-2019
【问题讨论】:
-
我不得不问:当 PHP 有广泛的 IMAP functions 范围时,为什么要在 Python 中这样做?
-
在团队中工作,这是我接棒的地方。不幸的是,现有代码在我当前的设置下无法在我的机器上运行。
-
您的 PYTHONPATH 或类似的东西在运行时被修改了,并且找不到它的支持 DLL(例如,内部的 _ssl 模块)。
-
我尝试对我的环境变量进行一些修改,但没有运气,再次更新正文以提供更多详细信息
标签: php python cmd git-bash imaplib