[英]AttributeError: … object has no attribute 'update'
I have the following code to download HTML content from a list of URLs. 我有以下代码从URL列表下载HTML内容。 Whenever I run it I get an error that says "Traceback (most recent call last):
每当我运行它时,我都会收到一条错误消息,指出“追踪(最近一次通话过去):
File "*******", line 16, in <module>
**hashMessage = computeMD5(url)**
File "*******", line 13, in computeMD5
**m.update(message)**
*AttributeError: 'builtin_function_or_method' object has no attribute 'update'*
and here is the code: 这是代码:
import hashlib
from hashlib import md5
import os
fh = open("****.txt", 'r')
for line in fh:
url = line
url = url.replace('\n', '')
def computeMD5(message):
m = hashlib.md5
m.update(message)
return m.hexdigest()
hashMessage = computeMD5(url)
print hashMessage
os.system(" wget -O /desktop/Html" + hashMessage + ".txt " + url)
How can I fix this? 我怎样才能解决这个问题?
You are attempting to call a method on a function and not an object. 您试图在函数而不是对象上调用方法。 Instead call:
而是调用:
import hashlib
from hashlib import md5
import os
fh = open("****.txt", 'r')
for line in fh:
url = line
url = url.replace('\n', '')
def computeMD5(message):
m = hashlib.md5() # instead of m = hashlib.md5
m.update(message)
return m.hexdigest()
hashMessage = computeMD5(url)
print hashMessage
os.system(" wget -O /desktop/Html" + hashMessage + ".txt " + url)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.