本文介绍了保存到运行dev_appserver的本地主机上的客户端库的GCS时出现404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用GCS进行文件存储的python GAE应用程序。它在生产环境中可以很好地工作,但是在dev_appserver上本地运行时完全失败。



任何有助于深入了解此内容的人都会受益。



谢谢。

CODE:

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

错误:

  INFO:root:default:POST /_ah/gcs/mybucket/foo.jpg HTTP / 1.1404 52 
ERROR 2013-11-12 07: 45:05,905 webapp2.py:1552]预期来自Google存储的状态[201]。但是得到状态404.
路径:u'/ mybucket / foo.jpg'。
请求标题:{'x-goog-resumable':'start','x-goog-api-version':'2','content-type':u'image / jpeg','accept-编码':'gzip,*'}。
响应标题:{'date':'Tue,2013年11月12日07:45:05 GMT','expires':'Fri,01 Jan 1990 00:00:00 GMT','content-type': 文本/无格式; 'charset = UTF-8','content-length':'52','server':'Development / 2.0','cache-control':'no-cache'}。
额外信息:无。
回溯(最近通话最后一个):
档/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2 py 为,线1535,在__call__
RV = self.handle_exception(请求,响应,E)
档 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/资源/ google_appengine / lib / webapp2-2.5.2 / webapp2.py,第1529行,在__call__
中rv = self.router.dispatch(请求,响应)
文件/Applications/GoogleAppEngineLauncher.app /Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py,第1278行,在default_dispatcher
INFO:root:default:POST / admin /项目HTTP / 1.1500 3587
返回route.handler_adapter(请求,响应)
文件/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/R esources / google_appengine / lib / webapp2-2.5.2 / webapp2.py,第1102行,在__call__
返回handler.dispatch()
文件/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine -default.bundle / Contents / Resources / google_appengine / lib / webapp2-2.5.2 / webapp2.py,第572行,发送
返回self.handle_exception(e,self.app.debug)
文件 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py,线路570,在调度
返回方法( * args,** kwargs)
文件/Users/me/myapp/admin.py,第194行,后
photo = self.create_image_entity(img_object)
文件/ Users /me/myapp/admin.py,第234行,在create_image_entity
self.write_file_to_gcs(filename = filename,file = img_data,content_type = img_object ['mimetype'])
文件/ Users / me /myapp/admin.py,第276行,在write_file_to_gcs
中gbs_file = gcs.open(filename,'w',content_type = content_type)

return open_api中打开/Users/me/myapp/external/cloudstorage/cloudstorage_api.py,第74行。 StreamingBuffer(API,文件名,CONTENT_TYPE,选项)
档 /Users/me/myapp/external/cloudstorage/storage_api.py,线路597,在__init__
errors.check_status(状态,[201] ,路径,头文件,resp_headers)
文件/Users/me/myapp/external/cloudstorage/errors.py,第108行,check_status
提出NotFoundError(msg)
NotFoundError:Expect Google存储的状态[201]。但是得到状态404.
路径:u'/ mybucket / foo.jpg'。
请求标题:{'x-goog-resumable':'start','x-goog-api-version':'2','content-type':u'image / jpeg','accept-编码':'gzip,*'}。
响应标题:{'date':'Tue,2013年11月12日07:45:05 GMT','expires':'Fri,01 Jan 1990 00:00:00 GMT','content-type': 文本/无格式; 'charset = UTF-8','content-length':'52','server':'Development / 2.0','cache-control':'no-cache'}。
额外信息:无。


解决方案

我遇到了同样的问题。
我使用google_appengine_1.8.7(来自zip)和appengine-gcs-client-python-r127.zip。

终点_ah / gcs不在dev_appserver中处理。



实际上,我认为它与此更改有关()和似乎是GAE 1.8.7。不符合这种变化。



我使用这个appengine-gcs-client-python-r65.zip,它现在工作正常!


I have a python GAE app that uses GCS for file storage. It works perfectly in production, but fails completely when running locally on dev_appserver.

Any help getting to the bottom of this would be appreciated.

Thanks.

CODE:

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

ERROR:

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.
解决方案

I got the same problem.I am using google_appengine_1.8.7 (from zip) and appengine-gcs-client-python-r127.zip.

The end point "_ah/gcs" is not handled in dev_appserver.

In fact i think it is related to this change (https://code.google.com/p/appengine-gcs-client/source/detail?r=125) and seems that the GAE 1.8.7. is not align with this change.

I use this appengine-gcs-client-python-r65.zip and it works fine now!

这篇关于保存到运行dev_appserver的本地主机上的客户端库的GCS时出现404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 11:36