7

ファイル ストレージに GCS を使用する Python GAE アプリがあります。本番環境では完全に機能しますが、dev_appserver でローカルに実行すると完全に失敗します。

これを理解するための助けがあれば幸いです。

ありがとう。

コード:

BUCKET = '/mybucket'
filename = BUCKET + '/foo.jpg'
gcs_file = gcs.open(filename, 'w', content_type=content_type)
gcs_file.write(file)
gcs_file.close()

エラー:

INFO:root:default: "POST /_ah/gcs/mybucket/foo.jpg HTTP/1.1" 404 52
ERROR 2013-11-12 07:45:05,905 webapp2.py:1552] Expect status [201] from Google Storage. But got status 404.
Path: u'/mybucket/foo.jpg'.
Request headers: {'x-goog-resumable': 'start', 'x-goog-api-version': '2', 'content-type': u'image/jpeg', 'accept-encoding': 'gzip, *'}.
Response headers: {'date': 'Tue, 12 Nov 2013 07:45:05 GMT', 'expires': 'Fri, 01 Jan 1990 00:00:00 GMT', 'content-type': 'text/plain; charset=UTF-8', 'content-length': '52', 'server': 'Development/2.0', 'cache-control': 'no-cache'}.
Extra info: None.
Traceback (most recent call last):
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1535, in __call__
      rv = self.handle_exception(request, response, e)
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1529, in __call__
      rv = self.router.dispatch(request, response)
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
INFO:root:default: "POST /admin/projects HTTP/1.1" 500 3587
        return route.handler_adapter(request, response)
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1102, in __call__
        return handler.dispatch()
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 572, in dispatch
        return self.handle_exception(e, self.app.debug)
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 570, in dispatch
        return method(*args, **kwargs)
    File "/Users/me/myapp/admin.py", line 194, in post
        photo = self.create_image_entity(img_object)
    File "/Users/me/myapp/admin.py", line 234, in create_image_entity
        self.write_file_to_gcs(filename=filename, file=img_data, content_type=img_object['mimetype'])
    File "/Users/me/myapp/admin.py", line 276, in write_file_to_gcs
       gcs_file = gcs.open(filename, 'w', content_type=content_type)
    File "/Users/me/myapp/external/cloudstorage/cloudstorage_api.py", line 74, in open
       return storage_api.StreamingBuffer(api, filename, content_type, options)
    File "/Users/me/myapp/external/cloudstorage/storage_api.py", line 597, in __init__
        errors.check_status(status, [201], path, headers, resp_headers)
    File "/Users/me/myapp/external/cloudstorage/errors.py", line 108, in check_status
        raise NotFoundError(msg)
NotFoundError: Expect status [201] from Google Storage. But got status 404.
Path: u'/mybucket/foo.jpg'.
Request headers: {'x-goog-resumable': 'start', 'x-goog-api-version': '2', 'content-type': u'image/jpeg', 'accept-encoding': 'gzip, *'}.
Response headers: {'date': 'Tue, 12 Nov 2013 07:45:05 GMT', 'expires': 'Fri, 01 Jan 1990 00:00:00 GMT', 'content-type': 'text/plain; charset=UTF-8', 'content-length': '52', 'server': 'Development/2.0', 'cache-control': 'no-cache'}.
Extra info: None.
4

2 に答える 2

3

私は同じ問題を抱えています。私は google_appengine_1.8.7 (zip から) と appengine-gcs-client-python-r127.zip を使用しています。

エンドポイント「_ah/gcs」はdev_appserverでは扱いません。

実際、この変更 ( https://code.google.com/p/appengine-gcs-client/source/detail?r=125 ) に関連していると思いますが、GAE 1.8.7. この変更に対応していません。

私はこの appengine-gcs-client-python-r65.zip を使用していますが、今では正常に動作しています!

于 2013-11-13T08:01:41.093 に答える
0

問題は、gcs ファイルの書き込みには承認が必要であることだと思います。本番環境で実行している場合、この手順で gcs に書き込むことが承認されているアプリを使用しています (ドキュメントに記載されています)。

BigQuery と Cloud Storage への API 呼び出しには承認が必要です。この Codelab では、App Engine サービス アカウントの認証方法を使用します。これらの API を呼び出すように App Engine アプリを設定するには:

Copy the App Engine service account name that we noted above (in the form of your_app_id@appspot.gserviceaccount.com).
Visit your API console's Team tab, and add the service account name to the project teammate with Can edit permissions.

ローカル サーバーで作業している間は、この権限がありません。

于 2013-11-12T07:31:03.187 に答える