我正在使用Blobstore API将文件从S3迁移到GCS。我创建了南数据迁移脚本来更新文件的元数据:
from google.appengine.ext import blobstore
from google.appengine.api import images
class Migration(DataMigration):
def forwards(self, orm):
images = orm['core.Image'].objects.all()
for image in images:
blob_key = blobstore.create_gs_key('/gs/mybucket/' + image.name)
try:
url = images.get_serving_url(blob_key)
except images.ObjectNotFoundError:
url = ''
image.url = url
image.save()
...
当我尝试在AppEngine项目中运行脚本时:
$ python manage.py migrate
我收到错误:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/user/Downloads/google_appengine/google/appengine/api/blobstore/blobstore.py", line 485, in create_gs_key
rpc = create_gs_key_async(filename, rpc)
File "/home/user/Downloads/google_appengine/google/appengine/api/blobstore/blobstore.py", line 525, in create_gs_key_async
lambda rpc: rpc.response.blob_key())
File "/home/user/Downloads/google_appengine/google/appengine/api/blobstore/blobstore.py", line 226, in _make_async_call
rpc = create_rpc()
File "/home/user/Downloads/google_appengine/google/appengine/api/blobstore/blobstore.py", line 220, in create_rpc
return apiproxy_stub_map.UserRPC('blobstore', deadline, callback)
File "/home/user/Downloads/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 413, in __init__
self.__rpc = CreateRPC(service, stubmap)
File "/home/user/Downloads/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 67, in CreateRPC
assert stub, 'No api proxy found for service "%s"' % service
AssertionError: No api proxy found for service "blobstore"
我看到manage.py
没有利用AppEngine开发服务器引导和身份验证。有谁知道如何解决这个问题?如何使用manage.py
中的AppEngine开发工具。
我查找了django-rocket-engine项目,该项目使用了类似的想法,但它已经很老了而且不受支持。某些API已被Google弃用。
答案 0 :(得分:0)
这不是我认为最佳的解决方案,但它可以解决问题。我使用AppEngine Remote API来使用blobstore和Django模型。您首先需要修改app.yaml
脚本:
# app.yaml
handlers:
- url: /remoteapi.*
script: google.appengine.ext.remote_api.handler.application
login: admin
然后使用remote_api_shell.py
脚本访问shell。您可以使用该脚本访问本地dev_appserver和远程appengine。对于本地dev_appserver,只需使用-s localhost:8080
。确保DATABASES
中的settings.py
设置正确,指向正确的数据库。
以下是使用Remote API shell的会话:
$GAE_SDK_ROOT/google_appengine/remote_api_shell.py -s APP-ID.appspot.com
Email: <admin-email>
Password:
App Engine remote_api shell
Python 2.7.5+ (default, Feb 27 2014, 19:39:55)
[GCC 4.8.1]
The db, ndb, users, urlfetch, and memcache modules are imported.
s~APP-ID> import os, sys
s~APP-ID> sys.path.insert(0, os.environ['GAE_SDK_ROOT'] + '/google_appengine/lib/django-1.5')
s~APP-ID> import django
s~APP-ID> django.VERSION
(1, 5, 4, 'final', 0)
s~APP-ID> sys.path.append('/home/user/myproject/myproject')
s~APP-ID> os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
'settings'
s~APP-ID> from google.appengine.ext import blobstore
s~APP-ID> from google.appengine.api import images
s~APP-ID> from myproject.core.models import Image
s~APP-ID> images = Image.objects.all()
s~APP-ID> for image in images:
... blob_key = blobstore.create_gs_key('/gs/mybucket/' + image.name)
... try:
... url = images.get_serving_url(blob_key)
... except images.ObjectNotFoundError:
... url = ''
... image.url = url
... image.save()