开发者

get(self) takes exactly 1 argument, 2 supplied - NOT

I am having a very odd error occurring in the following:

class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self, resource):
    iconKey = str(urllib.unquote(resource))

    if iconKey:
        blob_info = blobstore.get(iconKey)

        if blob_info:
            url = images.get_serving_url(blob_key=iconKey, size=200)

            self.response.out.write('<h1>%s</h1><small>%s</small><br/><br/><img src="%s" alt="%s">' % ('A Title', '11-26-1997', url, 'A Title'))

The response is this:

TypeError: get() takes exactly 1 argument (2 given)

The code is suposed to take the end of the URL request, pass that to the iconKey var, and use it as a blob key to access the blobstore for the image and create a serving url with the images.get_serving_url() method.

Anybody run into this before? I tried putting a @staticmethod parameter over the get definition, but of course, that made the get method not be able to access the request via self.

EDIT

I just changed something which got another error. I had been using the ([^/]+)? regexp for the URL - where the U开发者_运维百科RL would be /view/icon/76M5e-xIStHRJDYyXBXjDA== and the resource passed to the get() method would be the 76M5e-xIStHRJDYyXBXjDA== ending of the URL.

I just change the regexp to (.*) as per @systempuntoout's answer below. Now I get this error: AttributeError: split with this stack trace:

ERROR    2011-07-15 13:19:39,949 __init__.py:463] split
Traceback (most recent call last):
File "/Users/mac/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 700, in __call__
handler.get(*groups)
File "/Users/mac/icondatabase/main.py", line 72, in get
iconKey = str(urllib.unquote(self.request))
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib.py", line 1164, in unquote
File "/Users/mac/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob/webob/__init__.py", line 500, in __getattr__
raise AttributeError(attr)
AttributeError: split
INFO     2011-07-15 13:19:39,958 dev_appserver.py:4217] "GET /view/icon/76M5e-xIStHRJDYyXBXjDA== HTTP/1.1" 500 -
INFO     2011-07-15 13:19:40,250 dev_appserver.py:4217] "GET /favicon.ico HTTP/1.1" 404 -


You are probably not matching any resource group parameter in your URL regex configuration.

Be sure to have a rule like this in your main:

 application = webapp.WSGIApplication(
          [(r'/files/(.*)', ServeHandler)], debug=True)
    run_wsgi_app(application)

This will pass to the get() resource parameter of the ServeHandler instance, the string matched after the route /files/.

Example:
localhost:8080/files/A2312ODESDX will pass A2312ODESDX as resource


You'fre confusing the get methods of two different classes:

  • BlobstoreDownloadHandler.get has two arguments, self and resource.
  • webapp.RequestHandler.get takes only self
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜