使用Google Compute Engine时,'EntryPoint'对象没有属性'resolve'

时间:2016-09-09 14:31:39

标签: python django cryptography google-compute-engine

我在Python中遇到与Cryptography包有关的问题。如果可能的话,你能帮忙解决这些问题吗? (尝试了很多,但无法找出确切的解决方案)

启动此错误的python代码:

print("Salt: %s" % salt)
server_key = pyelliptic.ECC(curve="prime256v1")  # ----->> Line2
print("Server_key: %s" % server_key)   # ----->> Line3
server_key_id = base64.urlsafe_b64encode(server_key.get_pubkey()[1:])

http_ece.keys[server_key_id] = server_key
http_ece.labels[server_key_id] = "P-256"
encrypted = http_ece.encrypt(data, salt=salt, keyid=server_key_id,
            dh=self.receiver_key, authSecret=self.auth_key)  # ----->> Line8

“盐”的价值在100%的案例中显示。

如果 Line3 成功执行,由于http_ece.encrypt()调用( Line8 ),我看到以下入口点错误:

AttributeError("'EntryPoint' object has no attribute 'resolve'",)

(参考文件链接:https://github.com/martinthomson/encrypted-content-encoding/blob/master/python/http_ece/init.py#L128

Requirements.txt(部分):

cryptography==1.5
pyelliptic==1.5.7
pyOpenSSL==16.1.0

运行命令:sudo pip freeze --all |grep setuptools,我得到: setuptools==27.1.2

如果需要更多详细信息,请与我们联系。

这个问题似乎基本上是由于VM上安装了一些旧/不兼容的软件包(与PyElliptic,Cryptography,PyOpenSSL和/或setuptools相关)。供参考:https://github.com/pyca/cryptography/issues/3149

有人可以建议一个很好的解决方案来完全解决这个问题吗?

谢谢,

2 个答案:

答案 0 :(得分:3)

issue中引用的c66303382有这个追溯(你从未给过你的追溯,所以我必须假设你的结尾方式相同):

File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/backends/__init__.py", line 35, in default_backend
    _default_backend = MultiBackend(_available_backends())
File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/backends/__init__.py", line 22, in _available_backends
    "cryptography.backends"
触发错误的

The full line如下所示:

_available_backends_list = [
        ep.resolve()
        for ep in pkg_resources.iter_entry_points(
            "cryptography.backends"
        )
    ]

repository中搜索EntryPoint定义,然后blaming pkg_resources/__init__.py显示commit 92a553d3adeb431cdf92b136ac9ccc3f2ef98bf1(2015-01-05)中添加了pkg_resources.EntryPoint.resolve()进入setuptools v11.3

因此,如果您使用旧版本,则会看到此错误。

答案 1 :(得分:1)

从项目路径/ opt / projects / myproject-google / myproject中执行以下命令,它解决了Attribute EntryPoint错误问题:

(假设项目虚拟环境路径为:/ opt / projects / myproject-google / venv)

命令:(来自路径:/ opt / projects / myproject-google / myproject)

export PYTHONPATH=      # [Blank]
sudo pip install --upgrade virtualenv setuptools
sudo rm -rf ../venv
sudo virtualenv ../venv
source ../venv/bin/activate
sudo pip install --upgrade -r requirements.txt
deactivate

运行上述命令升级了虚拟环境&虚拟环境中的setuptools版本。位于路径:/opt/projects/myproject-google/venv/lib/python2.7/site-packages。要测试setuptools是否已成功升级,请尝试以下命令之一:

  1. 命令sudo virtualenv --version 输出15.0.3
  2. 命令echo $PYTHONPATH 输出:[空白]
  3. 命令python -c 'import pkg_resources; print(pkg_resources.__file__)' 输出~/.local/lib/python2.7/site-packages/pkg_resources/__init__.pyc
  4. 命令python -c 'import sys; print(sys.path)' 输出['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '~/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/opt/projects/myproject-google/myproject', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat']
  5. 命令ls /opt/projects/myproject-google/venv/lib/python2.7/site-packages输出easy_install.py pip pkg_resources setuptools-27.2.0.dist-info wheel-0.30.0a0.dist-info easy_install.pyc pip-8.1.2.dist-info setuptools wheel
  6. 命令python -c 'from cryptography.hazmat.backends import default_backend; print(default_backend())' 输出<cryptography.hazmat.backends.multibackend.MultiBackend object at 0x7ff83a838d50>
  7. 命令 /opt/projects/myproject-google/venv/bin/python -c 'from cryptography.hazmat.backends import default_backend; print(default_backend())'输出 Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named cryptography.hazmat.backends
  8. 命令/opt/projects/myproject-google/venv/bin/python -c "import pkg_resources; print(pkg_resources.__file__)" 输出/opt/projects/myproject-google/venv/local/lib/python2.7/site-packages/pkg_resources/__init__.pyc
  9. 参考链接:https://github.com/pyca/cryptography/issues/3149

    这些步骤使用更新版本的加密软件包完全解决了Attribute EntryPoint问题。 setuptools。

    更新截至2016年9月15日,加密团队再次添加了支持旧软件包的解决方法。 (参考链接:https://github.com/pyca/cryptography/issues/3150