0

だから私はいくつかのコードを持っています:

signature = hmac.new(
    key=AWS_SECRET_ACCESS_KEY,
    msg=string_to_sign,
    digestmod=hashlib.sha256).digest()

それは自分のコンピューターで完全に実行されます(python 2.6.1があります)。ただし、サーバー (Python 2.4.3) でこのコードを実行すると、次のようになります。

 /home/MYUSERNAME/public_html/Foo.com/cgi-bin/foo.py
   66     key=AWS_SECRET_ACCESS_KEY,
   67     msg=string_to_sign,
   68     digestmod=hashlib.sha1).digest()
   69  
   70 # Base64 encode the signature
digestmod = <built-in function openssl_sha256>, hashlib = <module 'hashlib' from '/usr/lib/python2.4/site-...shlib-20081119-py2.4-linux-i686.egg/hashlib.pyc'>, hashlib.sha1 = <built-in function openssl_sha1>, ).digest undefined
 /usr/lib/python2.4/hmac.py in new(key='xR6MsC/+Vc2xkd0YYbER0meR/IkWEU', msg='GET\necs.amazonaws.com\n/onca/xml\nAWSAccessKeyId=A...CommerceService&Timestamp=2010-07-03T18%3A56%3A48', digestmod=<built-in function openssl_sha1>)
  103     You can now feed arbitrary strings into the object using its update()
  104     method, and can ask for the hash value at any time by calling its digest()
  105     method.
  106     """
  107     return HMAC(key, msg, digestmod)
global HMAC = <class hmac.HMAC>, key = 'xR6MsC/+Vc2xkd0YYbER0meR/IkWEU', msg = 'GET\necs.amazonaws.com\n/onca/xml\nAWSAccessKeyId=A...CommerceService&Timestamp=2010-07-03T18%3A56%3A48', digestmod = <built-in function openssl_sha1>
 /usr/lib/python2.4/hmac.py in __init__(self=<hmac.HMAC instance>, key='xR6MsC/+Vc2xkd0YYbER0meR/IkWEU', msg='GET\necs.amazonaws.com\n/onca/xml\nAWSAccessKeyId=A...CommerceService&Timestamp=2010-07-03T18%3A56%3A48', digestmod=<built-in function openssl_sha1>)
   40 
   41         self.digestmod = digestmod
   42         self.outer = digestmod.new()
   43         self.inner = digestmod.new()
   44         self.digest_size = digestmod.digest_size
self = <hmac.HMAC instance>, self.outer undefined, digestmod = <built-in function openssl_sha1>, digestmod.new undefined

AttributeError: 'builtin_function_or_method' object has no attribute 'new'
      args = ("'builtin_function_or_method' object has no attribute 'new'",) 

私のサーバーで Python を更新するだけでよいことは明らかですが、私のホストはそれを行う必要があり、どれくらいの時間がかかるかわかりません。これが 2.4.3 の共通/既知の問題なのか、それとも何か他のことが起こっているのか、私はただ興味があります。

ありがとう

4

2 に答える 2

0

hashlib2.5 の新機能です。古いバージョンの Python にはバックポートが必要です。

于 2010-07-03T19:11:01.800 に答える