Running python version 2.4.3. I am using python-amazon-product-api. However in api.py the following lines of code is causing problem:

if sys.version_info[:2] > (2, 4): # pragma: no cover
    from urllib2 import quote
    from hashlib import sha256 # pylint: disable-msg=E0611
else:
    from urllib import quote
    from Crypto.Hash import SHA256 as sha256

As my version is 2.4.3 it go in to else and try to import Crypto. So i downloaded that but i got import error in SHA256.py cannot import _SHA256. There is no _SHA256.py in library. After all my unsuccessful efforts i quit to use pyCrypto and i try to use standalone hashlib library. So i modified else part in api.py:

else:
    from hashlib import hashlib
    sha256 = hashlib.sha256()

Then again while importing hashlib i got this import error.

File "C:\Python24\lib\site-packages\hashlib.py", line 63, in __get_builtin_constructor
    import _md5
ImportError: DLL load failed: The specified module could not be found.

I posted similar question yesterday but not able to find the exact solution that is why i am posting this again. I desperately need a solution :(

有帮助吗?

解决方案

Several questions based on what you've said above.

1) Why are you using an ancient version of Python? Install Python 2.7 and be happier!

2) assuming you're unfortunately stuck with 2.4 for some unknown reason... it appears that Python is unable to find any of the binary extension module (.pyd) files that came with the hashlib package you installed. Did you compile your own hashlib or install a binary version? If so, make sure the _hashlib.pyd file is put somewhere in the PYTHONPATH or sys.path.

I haven't had a windows installer with precompiled binaries for hashlib up on http://code.krypto.org/python/hashlib in years as I lack the ability to build and test it... and Python 2.4 is so old that I assume anyone with the ability to install a binary on their system can just install a modern version of Python itself.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top