Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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
Google app engine appengine dev_appserver.py,带有来自Google存储本地API的返回404的网页包_Google App Engine_Webpack - Fatal编程技术网

Google app engine appengine dev_appserver.py,带有来自Google存储本地API的返回404的网页包

Google app engine appengine dev_appserver.py,带有来自Google存储本地API的返回404的网页包,google-app-engine,webpack,Google App Engine,Webpack,我正在使用Google app Engine标准环境和Python开发一个应用程序,前端使用Webpack。应用程序将照片存储在Google存储中并显示它们。当我将应用程序部署到应用程序引擎时,一切正常 当我尝试运行本地dev_appserver.py和Webpack时,当我通过Webpack DevServer端口访问应用程序(在我的例子中是3001)时,尝试从Google存储API读取时,会出现以下异常。如果构建Webpack静态输出,并使用dev_appserver.py端口(8080)执

我正在使用Google app Engine标准环境和Python开发一个应用程序,前端使用Webpack。应用程序将照片存储在Google存储中并显示它们。当我将应用程序部署到应用程序引擎时,一切正常

当我尝试运行本地dev_appserver.py和Webpack时,当我通过Webpack DevServer端口访问应用程序(在我的例子中是3001)时,尝试从Google存储API读取时,会出现以下异常。如果构建Webpack静态输出,并使用dev_appserver.py端口(8080)执行完全相同的请求,我将获得照片

[appengine] ERROR    2017-08-26 20:19:18,786 photo_storage.py:31] Fail to read photo file
[appengine] Traceback (most recent call last):
[appengine]   File "c:\myapp\server\api\photo_storage.py", line 20, in read_photo_from_storage
[appengine]     file_stat = gcs.stat(filename)
[appengine]   File "c:\myapp\server\lib\cloudstorage\cloudstorage_api.py", line 151, in stat
[appengine]     body=content)
[appengine]   File "c:\myapp\server\lib\cloudstorage\errors.py", line 132, in check_status
[appengine]     raise NotFoundError(msg)
[appengine] NotFoundError: Expect status [200] from Google Storage. But got status 404.
[appengine] Path: '/app_default_bucket/pics/185804764220139124118/395ebb68_main.png'.
[appengine] Request headers: None.
[appengine] Response headers: {'date': 'Sat, 26 Aug 2017 20:19:18 GMT', 'connection': 'keep-alive', 'content-type': 'text/html; charset=utf-8', 'content-security-policy': "default-src 'self'", 'x-content-type-options': 'nosniff', 'x-powered-by': 'Express', 'content-length': '211'}.
[appengine] Body: ''.
[appengine] Extra info: None.
这是读取和写入文件的代码:

import logging
import os
import logging
import urllib

from google.appengine.api import app_identity

import cloudstorage as gcs

from models import Photo

def read_photo_from_storage(photo, label, response):
    bucket_name = os.environ.get('BUCKET_NAME',
                                 app_identity.get_default_gcs_bucket_name())

    filename = format_photo_file_name(bucket_name, photo.created_by_user_id, photo.crc32c, label)

    try:
        file_stat = gcs.stat(filename)
        gcs_file = gcs.open(filename)
        response.headers['Content-Type'] = file_stat.content_type
        response.headers['Cache-Control'] = 'private, max-age=31536000' # cache for upto 1 year
        response.headers['ETag'] = file_stat.etag
        response.write(gcs_file.read())
        gcs_file.close()

    except gcs.NotFoundError:
        logging.exception("Fail to read photo file")
        response.status = 404
        response.write('photo file not found')

def write_photo_to_storage(user_id, checksum, label, file_type, image_content):
    bucket_name = os.environ.get('BUCKET_NAME',
                                 app_identity.get_default_gcs_bucket_name())

    filename = format_photo_file_name(bucket_name, user_id, checksum, label)

    write_retry_params = gcs.RetryParams(backoff_factor=1.1)
    gcs_file = gcs.open(filename,
                        'w',
                        content_type=file_type,
                        options={'x-goog-meta-crc32c': "{0:x}".format(checksum)},
                        retry_params=write_retry_params)
    gcs_file.write(image_content)
    gcs_file.close()

def format_photo_file_name(bucket_name, user_id, checksum, label):
    return urllib.quote("/{0}/pics/{1}/{2:x}_{3}.png".format(bucket_name, user_id, checksum, label))