试图上传到我的本地主机。这是 HTML 位:
<form enctype="multipart/form-data" method="POST" action="http://localhost:8080/_ah/upload/ahRkZXZ-ZGV2LWN5YmVyc2NpZW5jZXIbCxIVX19CbG9iVXBsb2FkU2Vzc2lvbl9fGAsM"><input type="file" name="srcFile"><input type="submit" value="submit" name="submit"></form>
以下是标题:
响应标头:
Cache-Control no-cache
Content-Length 0
Content-Type text/html
Date Fri, 26 Oct 2012 19:19:56 GMT
Expires Fri, 01 Jan 1990 00:00:00 GMT
Server Development/1.0
请求标头:
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Connection keep-alive
Cookie __utma=111872281.1477928994.1342991890.1351271332.1351275008.45; __utmz=111872281.1342991890.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); dev_appserver_login="me@gmail.com:False:[[int]]"; __utmc=111872281; __utmb=111872281.13.10.1351275008
Host localhost:8080
Referer http://localhost:8080/diagnostics
User-Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0
来自上传流的请求标头:
Content-Length 451
Content-Type multipart/form-data; boundary=---------------------------19073888353745436471437703342
以下是我在 project/__init__.py 中处理请求的方式:
76 config.add_route('UHandler', '/uploads/test')
77 config.add_view(UploadHandler,
78 attr="post",
79 route_name='UHandler',
80 context=Root,
81 renderer='uploads.jinja2')
这是它命中的处理程序代码:
class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
pdb.set_trace()
在我运行的调试器中:
(Pdb) p self.get_uploads()
*** AttributeError: AttributeError("'Root' object has no attribute 'params'",)
(Pdb) p self
<cyberanatomy.view.uploads.UploadHandler object at 0x5130ad0>
(Pdb) p self.get_uploads('srcFile')
[]
(Pdb) p self.get_uploads('srcFile')[0]
*** IndexError: IndexError('list index out of range',)
(Pdb) dir(self)
['_BlobstoreUploadHandler__uploads', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'abort', 'app', 'dispatch', 'error', 'get_uploads', 'handle_exception', 'initialize', 'post', 'redirect', 'redirect_to', 'request', 'response', 'uri_for', 'url_for']
(Pdb) self.request.request.POST
MultiDict([(u'srcFile', FieldStorage(u'srcFile', u'Screen Shot 2012-09-21 at 12.47.19.png')), (u'submit', u'submit')]
(Pdb) p self.get_uploads('anyRandomString')
[]
在 get_uploads 函数中移动我的断点:google_appengine/google/appengine/ext/webapp/blobstore_handlers.py
(Pdb) dir(self.request.params)
*** AttributeError: 'Root' object has no attribute 'params'
(Pdb) dir(self.request.request.params)
['_MutableMapping__marker', '__abstractmethods__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__doc__', '__eq__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__iter__', '__len__', '__metaclass__', '__module__', '__ne__', '__new__', '__nonzero__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_abc_cache', '_abc_negative_cache', '_abc_negative_cache_version', '_abc_registry', '_readonly', 'add', 'clear', 'copy', 'dict_of_lists', 'dicts', 'extend', 'from_fieldstorage', 'get', 'getall', 'getone', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'mixed', 'pop', 'popitem', 'setdefault', 'update', 'values', 'view_list']
因此,将第 372 行从:
372 for key, value in self.request.params.items():
到:
372 for key, value in self.request.request.params.items():
结果是:
(Pdb) print self.get_uploads()
[<google.appengine.ext.blobstore.blobstore.BlobInfo object at 0x4a6eb50>]
(Pdb) self.get_uploads()[0]
<google.appengine.ext.blobstore.blobstore.BlobInfo object at 0x4a6eb50>
这是怎么回事?这是标题中的内容类型的问题吗?这是金字塔如何处理 project/__init__.py 中的请求的问题吗?这是appengine中的错误吗?