相关疑难解决方法(0)

Python 2.5上选择模块的问题

我在Python 2.5中有一个监听beanstalk队列的应用程序.它在我测试的所有机器上都能正常工作,除了我新购买的MacBook Pro.

在那台计算机上,当我尝试运行它时,我收到此错误:

Traceback (most recent call last):
  File "jobs.py", line 181, in <module>
    Jobs().start()
  File "jobs.py", line 154, in start
    self.jobQueue = Queue()
  File "src/utils/queue.py", line 16, in __init__
    self.connection = serverconn.ServerConn(self.server, self.port)
  File "src/beanstalk/serverconn.py", line 25, in __init__
    self.poller = select.poll()
AttributeError: 'module' object has no attribute 'poll'
Run Code Online (Sandbox Code Playgroud)

serverconn.py具有以下导入:

import socket, select
Run Code Online (Sandbox Code Playgroud)

当我尝试从命令行运行它时,它也会失败:

Python 2.5.1 (r251:54863, Jul 23 2008, 11:00:16) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information. …
Run Code Online (Sandbox Code Playgroud)

python macos beanstalkd

3
推荐指数
1
解决办法
3653
查看次数

为什么我在Python中得到错误的hmac结果而不是Perl?

我正在尝试使用sha-512来计算hmac.

Perl代码:

use Digest::SHA qw(hmac_sha512_hex);

$key = "\x0b"x20;
$data = "Hi There";

$hash = hmac_sha512_hex($data, $key);
print "$hash\n";
Run Code Online (Sandbox Code Playgroud)

并给出正确的哈希值

87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cde  
daa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854
Run Code Online (Sandbox Code Playgroud)

Python版本:

import hashlib, hmac

print hmac.new("\x0b"*20, "Hi There", hashlib.sha512).hexdigest()
Run Code Online (Sandbox Code Playgroud)

它给出了错误的哈希值

9656975ee5de55e75f2976ecce9a04501060b9dc22a6eda2eaef638966280182
477fe09f080b2bf564649cad42af8607a2bd8d02979df3a980f15e2326a0a22a
Run Code Online (Sandbox Code Playgroud)

任何想法为什么Python版本给我错误的哈希?

编辑:
版本是
darwin的Python 2.5.1(r251:54863,2009年1月13日,10:26:13)
[GCC 4.0.1(Apple Inc. build 5465)]

python perl hash hmac

2
推荐指数
1
解决办法
3053
查看次数

标签 统计

python ×2

beanstalkd ×1

hash ×1

hmac ×1

macos ×1

perl ×1