我对python很陌生,我写了这段代码
def geturl(url):
url = urllib.quote(url,'/:')
log( __name__ ,"Getting url:[%s]" % url)
try:
req = urllib2.Request(url)
response = urllib2.urlopen(req)
content = response.read()
return_url = response.geturl()
response.close()
except Exception, e:
log( __name__ ,"Failed to get url because %s" % str(e))
content = None
return_url = None
return(content, return_url)
def myFunc():
searchurl="http://www.google.com"
socket.setdefaulttimeout(3)
content, response_url = geturl(searchurl)
if content is None:
log( __name__ , "Content is None!!")
content = content.replace("string1", "string2")
当我运行它时,我收到此错误:NoneType 对象不可调用。我不明白为什么......我了解到 NoneType 是 None 的类型,但我检查“content”变量是否为 None 并且不是。谢谢你的帮助