2
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)
4

1 に答える 1

1

完全なトレースバックを投稿する必要があります。ここに表示するものは、それほど有用ではありません。pyamf / util /init.pyの15行目を掘り下げることになりまし。投稿すべきコードは

from pyamf import python

ローカル環境が台無しにされない限り、これは失敗しないはずです。

インタラクティブなPythonシェルで「pyamf.utilをインポート」および「pyamf.pythonをインポート」できますか?/ tmpにいる間にPythonを起動した場合はどうでしょうか(現在のディレクトリに「pyamf.py」という名前のファイルがあると仮定します。これは悪いことです)。

=(以下の古いコメント)=

質問を修正してください。util / __init__。pyの15行目がどこにあるのかさえわかりません。それがわからないので、あなたの質問には答えられません。代わりに、質問とコードを改善する方法を指摘します。

まず、マークアップ言語を正しく使用して、すべてのコードがコードブロックに含まれるようにします。コードにタイトルを付けていることを確認してください。これにより、コードがutil / __ init __。pyからのものであり、ランダムなファイルではないことがわかります。

エラーメッセージには、最後の2行ではなく、完全なトレースバックを含めます。

「if(notservice_func):」などでparensの使用を停止し、代わりにスペースを使用して、「if not service_func:」にします。これについては、PEP8で説明されています。

Pythonのドキュメントを読み、言語の使用方法を学びます。「func_name=パス[len(パス)-1]」のようなものは「func_name=パス[-1]」である必要があります

インポート機能について学び、この場合は「exec」を使用しないでください。「execassign_string」も必要ありません。「self.addService(service_func、target)」を実行するだけです。

于 2010-09-18T05:00:59.893 に答える