3

ウィキペディアからテキストをスクレイピングしようとしています。httplib2 は既にインストールされているので、それを使用することにしました。

基本的な例から簡単に検索すると、最初の例でこのエラーが発生します。

> import httplib2
> h = httplib2.Http(".cache")
> url = "http://code.google.com/p/httplib2/"
> h.request(url, "GET")

Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/httplib2/__init__.py", line 978, in request
  cached_value = self.cache.get(cachekey)
 File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/httplib2/__init__.py", line 625, in get
  cacheFullPath = os.path.join(self.cache, self.safe(key))
 File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/httplib2/__init__.py", line 189, in safename
  filemd5 = md5.new(filename).hexdigest()
AttributeError: 'builtin_function_or_method' object has no attribute 'new'

Mac OS X、Python バージョン: 7.2-2 (64 ビット)、Enthought ディストリビューションで実行しています。

インストールに問題があるのではないかと思いますが、httplib2 は、私が使用している他のパッケージと共にインストールされました。また、httplib2 を再インストールすることもできますが、現在動作している他の機能が壊れる可能性があるため、躊躇しています。

4

1 に答える 1

2

Because the md5 module was deprecated (see http://docs.python.org/library/md5.html), httplib2 has code that checks dynamically for the old md5.new function or the new hashlib.md5 function. It's near the top of the module, and in the version that I have it looks like this:

# remove depracated warning in python2.6
try:
    from hashlib import sha1 as _sha, md5 as _md5
except ImportError:
    import sha
    import md5
    _sha = sha.new
    _md5 = md5.new

My guess is that your version of httplib2 is either too old and does not have this code, or it's going wrong somehow.

If you do have the newest version (or for some reason are unable/unwilling to upgrade), you can probably fix it dynamically in your program, but I'm not going to continue in that line, in the hope that upgrading will fix it.

于 2012-03-04T20:19:25.540 に答える