Python get(self)只接受1个参数,提供了2个-不是
我在以下方面出现了一个非常奇怪的错误:Python get(self)只接受1个参数,提供了2个-不是,python,google-app-engine,blobstore,Python,Google App Engine,Blobstore,我在以下方面出现了一个非常奇怪的错误: class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler): def get(self, resource): iconKey = str(urllib.unquote(resource)) if iconKey: blob_info = blobstore.get(iconKey) if blob_info: u
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'))
代码用于获取URL请求的结尾,将其传递给iconKey
var,并将其用作blob键,以访问图像的blob存储库,并使用图像创建一个服务URL。get\u serving\u URL()
方法
以前有人碰到过这个吗?我尝试在get
定义上放置一个@staticmethod
参数,但是当然,这使得get
方法无法通过self
访问请求
编辑
我刚更改了一些内容,但又出现了另一个错误。我一直在使用([^/]+)?
regexp作为URL,其中URL是/view/icon/76M5e-xisthrjdyxbxjda=
,传递给get()
方法的资源是URL的76M5e-xisthrjdyxbxjda=
结尾
我只是根据@systempuntoout下面的答案将regexp更改为(.*)
。现在我得到了这个错误:AttributeError:split
和这个堆栈跟踪:
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 -
您经常混淆两个不同类的
get
方法:
有两个参数,BlobstoreDownloadHandler.get
和self
resource
只接受webapp.RequestHandler.get
self
get
方法:
有两个参数,BlobstoreDownloadHandler.get
和self
resource
只接受webapp.RequestHandler.get
self
资源
组参数
请确保在主菜单中有这样一条规则:
application = webapp.WSGIApplication(
[(r'/files/(.*)', ServeHandler)], debug=True)
run_wsgi_app(application)
这将传递给ServeHandler实例的get()resource
参数,该字符串在路由/files/
后匹配
示例:localhost:8080/files/A2312ODESDX
将作为resource
传递A2312ODESDX
,您可能没有匹配URL正则表达式配置中的任何资源
组参数
请确保在主菜单中有这样一条规则:
application = webapp.WSGIApplication(
[(r'/files/(.*)', ServeHandler)], debug=True)
run_wsgi_app(application)
这将传递给ServeHandler实例的get()resource
参数,该字符串在路由/files/
后匹配
示例:localhost:8080/files/A2312ODESDX
将A2312ODESDX
作为resource
传递,但我使用的是BlobstoreDownloadHandler.get
方法,和resource
参数。将处理程序更改为webapp.RequestHandler
并删除resource
参数没有任何影响。@Crossdiver我假设有问题的行是blob\u info=blobstore.get(iconKey)
。在这种情况下,blobstore
是什么?它的类型是什么?BlobstoreDownloadHandler
是RequestHandler
的子类RequestHandler.get()
可以接受任意数量的参数-它获取的参数取决于匹配URL模式中的正则表达式组。但是我使用的是BlobstoreDownloadHandler.get
方法,和resource
参数。将处理程序更改为webapp.RequestHandler
并删除resource
参数没有任何影响。@Crossdiver我假设有问题的行是blob\u info=blobstore.get(iconKey)
。在这种情况下,blobstore
是什么?它的类型是什么?BlobstoreDownloadHandler
是RequestHandler
的子类RequestHandler.get()
可以接受任意数量的参数-它获取的参数取决于匹配URL模式中的正则表达式组。请将整个stacktrace以及此处理程序的路由定义包括在内,好吗?您确定在将resource
参数添加到get()
之前的版本中没有看到此错误吗?这是源格式中的错误还是代码缩进错误?这会导致您看到的错误。@Chris-是的,是错误@Nick-将使用堆栈跟踪进行更新。请将整个堆栈跟踪与此处理程序的路由定义一起包括在内,好吗?您确定在将resource
参数添加到get()
之前的版本中没有看到此错误吗?这是源格式中的错误还是代码缩进错误?这会导致您看到的错误。@Chris-是的,是错误@尼克-将更新堆栈跟踪。啊哈!!现在至少我又犯了一个错误<代码>属性错误:拆分。还没有用谷歌搜索过。错误显示为iconKey=str(urllib.unquote(self.request))
,您的代码显示为iconKey=str(urllib.unquote(resource))
Garh!!现在它给了我一个无用的“NotImplementedError:找不到Python PIL库。
”好了,现在我们很快就能看到一些东西了。为了使用development server.Aha中的google.appengine.api.images
模块,您应该安装PIL!!非常感谢你。。。让我试试。啊哈!!现在至少我又犯了一个错误<代码>属性错误:拆分。还没有用谷歌搜索过。错误显示为iconKey=str(urllib.unquote(self.request))
,您的代码显示为iconKey=str(urllib.unquote(resource))
Garh!!现在它给了我一个无用的“NotImplementedError:找不到Python PIL库。
”好了,现在我们很快就能看到一些东西了。为了使用development server.Aha中的google.appengine.api.images
模块,您应该安装PIL!!非常感谢你。。。让我试试。