开发者

Error when trying to assign blob object

The following 开发者_StackOverflow中文版code

for h in hits:
    urls.append(h['url'])
    result = db.Blob(urlfetch.Fetch(h['url']).content)
    model.image = result

returns the error

cannot concatenate 'str' and 'NoneType' objects.


Use some debug printing to find out if urlfetch.Fetch(h['url']).content is even returning anything. Based on the error, the result is None and db.Blob() is expecting the result to be a string.

If so, plan accordingly by checking the value of content before trying to apply it. And maybe a little error tracking for good measure?

Here's a simple example:

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


I see concatenation only on this line:

urls.append(h['url'])

judging by error: 'String' would be urls, and 'NoneType' would be h['url'] Most likely h['url'] is empty. Make sure of this by printing it to console.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜