问题描述
我有一个与Python中的加密包有关的问题。如果可能,你能帮助解决这些问题吗? (尝试了很多,但couldnt找出确切的解决方案)
启动此错误的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
Salt的值在100%的情况下显示。
如果 Line3 成功执行,我会看到以下EntryPoint错误,因为调用http_ece.encrypt():
AttributeError('EntryPoint'对象没有属性'resolve',)
(参考文件链接:) / p>
Requirements.txt(部分):
cryptography == 1.5
pyelliptic == 1.5.7
pyOpenSSL == 16.1.0
运行时命令: sudo pip freeze --all | grep setuptools
,我得到:
setuptools == 27.1.2 $ c $
这个问题似乎基本上是因为到安装在VM上的一些旧/不兼容的包(与PyElliptic,Cryptography,PyOpenSSL和/或setuptools相关)。供参考:
有人可以建议一个好的解决方案来完全解决这个问题吗?
谢谢,
从项目路径/ opt / projects / myproject-google / myproject中移除以下命令,并解决了属性EntryPoint错误问题:
(假设项目虚拟环境路径为:/ opt / projects / myproject-google / venv)
命令: 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是否已成功升级,请尝试以下某些命令:
- 命令:
sudo virtualenv --version
输出:15.0.3
- 命令:
echo $ PYTHONPATH
输出:[blank] - 命令:
python -c'import pkg_resources; print(pkg_resources .__ file __)'
输出:〜/ .local / lib / python2.7 / site-packages / pkg_resources / __init __。pyc
- 命令:
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']
- 命令:
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 - Command :
python -c'from cryptography.hazmat.backends import default_backend; print(default_backend())'
输出:< cryptography.hazmat.backends.multibackend.MultiBackend object at 0x7ff83a838d50& code>
- 命令
/ opt / projects / myproject- google / venv / bin / python -c' hazmat.backends import default_backend; print(default_backend())'
输出
回溯$ b< module>中的文件< string>,第1行
ImportError:没有模块命名cryptography.hazmat.backends
- 命令:
/ opt / projects / myproject-google / venv / bin / python -cimport pkg_resources; print(pkg_resources .__ file __)
输出:/opt/projects/myproject-google/venv/local/lib/python2.7/site-packages/pkg_resources / __ init __。pyc
参考链接:
这些步骤完全使用加密软件包&
更新。截至2016年9月15日,Cryptography团队再次添加了支持旧包的解决方法。(参考链接:)
I have an issue related to Cryptography package in Python. Can you please help in resolving these, if possible ? (tried a lot, but couldnt figure out the exact solution)
The python code which initiates this error:
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
Value of "Salt" is getting displayed in 100% of the cases.
If Line3 gets executed successfully, I see the the following EntryPoint Error because of http_ece.encrypt() call (Line8):
AttributeError("'EntryPoint' object has no attribute 'resolve'",)
(Ref. File Link: https://github.com/martinthomson/encrypted-content-encoding/blob/master/python/http_ece/init.py#L128 )
Requirements.txt(partial):
cryptography==1.5
pyelliptic==1.5.7
pyOpenSSL==16.1.0
On Running the command: sudo pip freeze --all |grep setuptools
, I get:setuptools==27.1.2
Please let me know if any more detail is required.
This problem seems to be basically due to some Old/Incompatible packages(related to PyElliptic, Cryptography, PyOpenSSL and/or setuptools) installed on the VM. For Reference: https://github.com/pyca/cryptography/issues/3149
Can someone please suggest a good solution to resolve this issue completely ?
Thanks,
Ran Following Commands from the project path /opt/projects/myproject-google/myproject and it resolved the Attribute EntryPoint Error Issue:
(Assuming project virtual env path as: /opt/projects/myproject-google/venv)
Command: (from path: /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
Running the above commands upgraded the virtual environment & the setuptools version inside the virtual Env. located at path: /opt/projects/myproject-google/venv/lib/python2.7/site-packages. To test if setuptools have upgraded successfully, try some of these commands:
- Command:
sudo virtualenv --version
Output:15.0.3
- Command:
echo $PYTHONPATH
Output: [blank] - Command:
python -c 'import pkg_resources; print(pkg_resources.__file__)'
Output:~/.local/lib/python2.7/site-packages/pkg_resources/__init__.pyc
- Command:
python -c 'import sys; print(sys.path)'
Output:['', '/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']
- Command:
ls /opt/projects/myproject-google/venv/lib/python2.7/site-packages
Output:easy_install.py pip pkg_resources setuptools-27.2.0.dist-info wheel-0.30.0a0.dist-infoeasy_install.pyc pip-8.1.2.dist-info setuptools wheel
- Command:
python -c 'from cryptography.hazmat.backends import default_backend; print(default_backend())'
Output:<cryptography.hazmat.backends.multibackend.MultiBackend object at 0x7ff83a838d50>
- Command
/opt/projects/myproject-google/venv/bin/python -c 'from cryptography.hazmat.backends import default_backend; print(default_backend())'
OutputTraceback (most recent call last):File "<string>", line 1, in <module>ImportError: No module named cryptography.hazmat.backends
- Command:
/opt/projects/myproject-google/venv/bin/python -c "import pkg_resources; print(pkg_resources.__file__)"
Output:/opt/projects/myproject-google/venv/local/lib/python2.7/site-packages/pkg_resources/__init__.pyc
Ref Link: https://github.com/pyca/cryptography/issues/3149
These Steps resolved the Attribute EntryPoint Issue completely with an updated version of cryptography package & the setuptools.
Update As on 15 September 2016, The Cryptography Team has again added the workaround for supporting old packages too.(Ref. Link: https://github.com/pyca/cryptography/issues/3150 )
这篇关于'EntryPoint'对象在使用Google Compute Engine时没有属性“resolve”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!