如何在OSX上安装Python SSL模块?

4
当我部署我的Google App Engine项目时,出现以下警告:
WARNING appengine_rpc.py:399 ssl module not found.
Without the ssl module, the identity of the remote host cannot be verified, and
connections may NOT be secure. To fix this, please install the ssl module from
http://pypi.python.org/pypi/ssl.

我已经下载了这个软件包,但是在尝试使用时遇到了问题。
python setup.py build

我收到了如下错误输出:
looking for /usr/include/openssl/ssl.h
looking for /usr/local/ssl/include/openssl/ssl.h
looking for /usr/contrib/ssl/include/openssl/ssl.h
Traceback (most recent call last):
  File "setup.py", line 167, in <module>
    ssl_incs, ssl_libs, libs = find_ssl()
  File "setup.py", line 142, in find_ssl
    raise Exception("No SSL support found")
Exception: No SSL support found

我需要做什么来安装它,是路径问题还是其他原因?

正如警告所述,您不必安装SSL模块。您有理由怀疑是否有人想要对您与App Engine服务器的连接进行中间人攻击吗? - Nick Johnson
3个回答

5

首先按照这里的说明安装pycrypto,然后根据这个问题中的答案提供的见解来修复问题。

最终构建使用的完整命令行如下:

CC='/usr/bin/gcc-4.0' python2.5 setup.py build

谢谢。你的命令行帮我按照谷歌的指导成功编译了 Python 的 SSL。此外,我还不得不重新安装 XCode,因为我没意识到未来可能还需要 OS 10.4 的 SDK。希望一切顺利。 - TheJacobTaylor

2

无论是10.5还是10.6,预装的Apple Python都包含ssl模块(较早版本不确定):

Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ssl.__file__
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ssl.pyc'

(来自10.5.8)

即使您已经启用了ssl,您仍然可能从appengine_rpc.py获得该错误消息 - 您需要确保您的GAE下载包含:

/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cacerts/cacerts.txt

如果您两者都具备,请尝试执行以下操作:
import google.appengine.tools.https_wrapper

这应该可以在原版的苹果Python中运行,但如果不能,错误信息可能更加详细。如果您安装了多个Python,其中一个会影响GAE的运行,请确保在GAE使用Python路径首选项指向苹果Python。


GAE使用的是Python 2.5,而不是系统默认安装的Python 2.6。 - Curyous

0

您可能需要手动安装openssl,尽管默认的Xcode安装应该将头文件放置在/usr/include中。(如果您没有安装Xcode,则您的机器上可能没有gcc,并且构建过程中会在后面失败。)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接