File "G:\Python25\Lib\site-packages\PyAMF-0.6b2-py2.5-win32.egg\pyamf\util\__init__.py", line 15, in <module>
ImportError: cannot import name python
我该如何解决? 如果您需要任何信息来了解如何解决这个问题,我可以解释一下,只是问一下。
由于
代码:
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import webapp
from TottysGateway import TottysGateway
import logging
def main():
services_root = 'services'
#services = ['users.login']
#gateway = TottysGateway(services, services_root, logger=logging, debug=True)
#app = webapp.WSGIApplication([('/', gateway)], debug=True)
#run_wsgi_app(app)
if __name__ == "__main__":
main()
代码:
from pyamf.remoting.gateway.google import WebAppGateway
import logging
class TottysGateway(WebAppGateway):
def __init__(self, services_available, root_path, not_found_service, logger, debug):
# override the contructor and then call the super
self.services_available = services_available
self.root_path = root_path
self.not_found_service = not_found_service
WebAppGateway.__init__(self, {}, logger=logging, debug=True)
def getServiceRequest(self, request, target):
# override the original getServiceRequest method
try:
# try looking for the service in the services list
return WebAppGateway.getServiceRequest(self, request, target)
except:
pass
try:
# don't know what it does but is an error for now
service_func = self.router(target)
except:
if(target in self.services_available):
# only if is an available service import it's module
# so it doesn't access services that should be hidden
try:
module_path = self.root_path + '.' + target
paths = target.rsplit('.')
func_name = paths[len(paths) - 1]
import_as = '_'.join(paths) + '_' + func_name
import_string = "from "+module_path+" import "+func_name+' as service_func'
exec import_string
except:
service_func = False
if(not service_func):
# if is not found load the default not found service
module_path = self.rootPath + '.' + self.not_found_service
import_string = "from "+module_path+" import "+func_name+' as service_func'
# add the service loaded above
assign_string = "self.addService(service_func, target)"
exec assign_string
return WebAppGateway.getServiceRequest(self, request, target)
答案 0 :(得分:1)
您需要发布完整的回溯。你在这里展示的并不是那么有用。我最终挖掘了pyamf / util / init .py的第15行。您应该发布的代码是
from pyamf import python
除非您的本地环境搞砸了,否则不会失败。
你可以在交互式Python shell中导入pyamf.util和'import pyamf.python'吗?如果你在/ tmp中启动Python怎么样(假设你当前目录中可能有一个名为'pyamf.py'的文件。这是一件坏事。)
=(以下较旧的评论)=
修正你的问题。我甚至无法分辨util / __ init__.py的第15行应该是什么。既然我无法弄明白,我无法回答你的问题。相反,我会指出改进问题和代码的方法。
首先,正确使用标记语言,以便所有代码都在代码块中。确保你已经标题代码,所以我们知道它来自util / __ init__.py而不是一些随机文件。
在错误消息中,包含完整回溯,而不是最后两行。
停止在诸如“if(not service_func):”之类的事情中使用parens,而是使用空格,所以它的“if not service_func:”。这在PEP 8中进行了讨论。
阅读Python文档并学习如何使用该语言。像“func_name = paths [len(paths) - 1]”之类的东西应该是“func_name = paths [-1]”
了解import函数,不要在这种情况下使用“exec”。你也不需要“exec assign_string” - 只需要做“self.addService(service_func,target)”