Python 尝试分配blob对象时出错
下面的代码Python 尝试分配blob对象时出错,python,django,google-app-engine,Python,Django,Google App Engine,下面的代码 for h in hits: urls.append(h['url']) result = db.Blob(urlfetch.Fetch(h['url']).content) model.image = result 返回错误 无法连接'str'和'str' “非类型”对象 使用一些调试打印来确定urlfetch.Fetch(h['url'])。content甚至返回任何内容。根据错误,结果是None和db.Blob()希望结果是字符串 如果是,则在尝试应用
for h in hits:
urls.append(h['url'])
result = db.Blob(urlfetch.Fetch(h['url']).content)
model.image = result
返回错误
无法连接'str'和'str'
“非类型”对象
使用一些调试打印来确定
urlfetch.Fetch(h['url'])。content
甚至返回任何内容。根据错误,结果是None
和db.Blob()
希望结果是字符串
如果是,则在尝试应用内容之前,通过检查内容的值进行相应的计划。也许有一点错误跟踪是为了更好的测量
下面是一个简单的例子:
errors = []
for h in hits:
urls.append(h['url'])
content = urlfetch.Fetch(h['url']).content
if content is not None:
result = db.Blob(urlfetch.Fetch(h['url']).content)
else:
print 'No content for', h['url']
errors.append(h)
continue
model.image = result
我仅在这一行中看到连接:
url.append(h['url'])
根据错误判断:“String”将是url,“NoneType”将是h['url']
很可能h['url']是空的。通过将其打印到控制台来确保这一点。Python中的字符串没有append
方法-URL
显然是一个列表。