Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试分配blob对象时出错_Python_Django_Google App Engine - Fatal编程技术网

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
显然是一个列表。