AttributeError(“'str' object has no attribute 'read'”)
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In Python I'm getting an error: Exception: ( , AttributeError("'str' object has no attribute 'read'",), ) Given python code: def getEntries (self, sub): url = 'http://www.reddit.com/' if (sub != ''): url += 'r/' + sub request = urllib2.Request (url + '.json', None, {'User-Agent' : 'Reddit desktop client by /user/RobinJ1995/'}) response = urllib2.urlopen (request) jsonofabitch = response.read () return json.load (jsonofabitch)['data']['children'] What does this error mean and what did I do to cause it? 回答1: The problem is that for json.load