Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python get(self)只接受1个参数,提供了2个-不是_Python_Google App Engine_Blobstore - Fatal编程技术网

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

您可能没有匹配URL正则表达式配置中的任何
资源
组参数

请确保在主菜单中有这样一条规则:

 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!!非常感谢你。。。让我试试。