Sunday, September 18, 2016

'EntryPoint' object has no attribute 'resolve' when using Google Compute Engine

Leave a Comment

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,

2 Answers

Answers 1

The issue referenced in c66303382 has this traceback (you never gave your traceback so I have to assume yours ends the same way):

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 that triggers the error looks like this:

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

Searching the repository for EntryPoint definition, then blaming pkg_resources/__init__.py where it is reveals that pkg_resources.EntryPoint.resolve() was added in commit 92a553d3adeb431cdf92b136ac9ccc3f2ef98bf1 (2015-01-05) that went into setuptools v11.3.

Thus you'll see this error if you use an older version.

Answers 2

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:

  1. Command: sudo virtualenv --version Output: 15.0.3
  2. Command: echo $PYTHONPATH Output: [blank]
  3. Command: python -c 'import pkg_resources; print(pkg_resources.__file__)' Output: ~/.local/lib/python2.7/site-packages/pkg_resources/__init__.pyc
  4. 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']
  5. 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-info easy_install.pyc pip-8.1.2.dist-info setuptools wheel
  6. Command: python -c 'from cryptography.hazmat.backends import default_backend; print(default_backend())' Output: <cryptography.hazmat.backends.multibackend.MultiBackend object at 0x7ff83a838d50>
  7. Command /opt/projects/myproject-google/venv/bin/python -c 'from cryptography.hazmat.backends import default_backend; print(default_backend())' Output Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named cryptography.hazmat.backends
  8. 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 )

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment