繁体   English   中英

映像迁移方法不适用于生产环境,但可以在本地主机中使用

[英]Image migration method not working in production, but works in localhost

我使用用于GAE的Files API编写了以下方法,用于将图像从我的SQL服务器迁移到GAE Blobstore。

import urllib2,csv
from abc.model import *
from google.appengine.api import files
from google.appengine.ext import ndb, blobstore
from urllib2 import HTTPError


def foo():
    i = []
    j = []
    csv_reader = csv.reader(open('tbl_property_images.csv','r'))
    csv_prop = csv.reader(open('property.csv','r'))
    ids = []
    for ele in csv_prop:
        ids.append(ele[0])
    for row in csv_reader:
        i.append(row[2])
        j.append(row[3])
    i = iter(i)
    j = iter(j)
    k = list(zip(i, j))
    d = {}
    for x, y in k:
        if x in d:
            d[x] = d[x] + [y]
    else:
            d[x] = [y]
d.pop('fld_property_id')
to_put = []
for ab in d.iterkeys():
    if ab in ids:
        for b in d[ab]:
            url = 'abc###.com/%s' % b
            try:
                file_name = files.blobstore.create(mime_type='image/jpeg')

                image = urllib2.urlopen(url)
                with files.open(file_name, 'a') as f:
                    f.write(image.read())
                files.finalize(file_name)
                blob_key = files.blobstore.get_blob_key(file_name)
                blob_info = blobstore.BlobInfo.get(blob_key)
                kwargs = {}
                kwargs['id'] = File.allocate_ids(1)[0]
                kwargs['identifier'] = '%s-%s' % (kwargs['id'], blob_info.filename)
                file = File(filename=blob_info.filename, content_type=blob_info.content_type, size=blob_info.size, blob=blob_info.key(), **kwargs)
                prop = Property.query(Property.id == ab).get()
                image1 = Image.build(file=file, property=prop.key)
                prop.image_url = image1.image_url
                to_put.append(prop)
                to_put.append(file)
                # if prop.key not in to_put properties key
                to_put.append(image1)

            except HTTPError:
                print url
                continue

ndb.put_multi(to_put)

如果我从本地主机的Interactive Console运行它,它将正常工作。 但在进入生产网站时会中断。

我的日志中出现以下错误。

追溯(最近一次通话):文件“”,第1行,在

在foo中的文件“ temp_part2.py”,第39行

f.write(image.read())

出口的文件“ /home/rohit/workspace/google_appengine/google/appengine/api/files/file.py”,第300行

self.close()

关闭文件“ /home/rohit/workspace/google_appengine/google/appengine/api/files/file.py”,第294行

self._make_rpc_call_with_retry('Close', request, response)

_make_rpc_call_with_retry中的文件“ /home/rohit/workspace/google_appengine/google/appengine/api/files/file.py”,第430行

_make_call(method, request, response)

_make_call _raise_app_error(e)中的文件“ /home/rohit/workspace/google_appengine/google/appengine/api/files/file.py”第255行

在_raise_app_error中,文件“ /home/rohit/workspace/google_appengine/google/appengine/api/files/file.py”第198行

raise FileNotOpenedError(e)

FileNotOpenedError:ApplicationError:10

我在此错误上停留了一段时间,我们将不胜感激。

看到另一个类似的问题, https://stackoverflow.com/a/18308034/1686094

将文件保持打开状态超过30秒也会导致此错误。 尝试将写入分为多个写入。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM