Question

Trying to upload to my local host. Here's the HTML bit:

<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>

Here are headers:

Response Headers:

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

Request Headers:

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

Request Headers From Upload Stream:

Content-Length  451
Content-Type    multipart/form-data; boundary=---------------------------19073888353745436471437703342

Here's how I handle the request in 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')

here's the handler code it hits:

   class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
       def post(self):
           pdb.set_trace()

In the debugger I run:

(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')
[]

Moving my breakpoint inside the get_uploads function: 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']

so, changing line 372 there from:

372       for key, value in self.request.params.items():

to:

372       for key, value in self.request.request.params.items():

results in:

(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>

What's going on? Is this an issue with the content type in the header? Is this an issue with how pyramid is processing the request in project/__init__.py? Is this a bug in appengine?

Was it helpful?

Solution

Well I have no idea what your BlobStoreUploadHandler base class is doing, but it appears as if it has set self.request as your context, considering that self.request.params is returning AttributeError: 'Root' object has no attribute 'params' and your view is configured to match a context of type Root.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top