2016-04-02 54 views
1

我正在看一個教程,以獲得一個基本的Web應用程序說「你好,世界」 但由於某種原因,我不明白,我得到這個 「本地主機頁面不工作 本地主機當前無法處理這個請求。」基本的網絡應用程序說「你好,世界。」

這就是我所做的。 1.我安裝了用於python的Google App Engine SDK。 2.我創建了兩個文件是這樣的:

main.py

import webapp2 

class MainPage(webapp2.RequestHandler): 
    def get(self): 
     self.response.headers['Content-Type'] = 'text/plain' 
     self.response.write('Hello, World!') 

app = webapp2.WSGIApplication([ 
    ('/', MainPage), 
], debug=True) 

的app.yaml

runtime: python27 
api_version: 1 
threadsafe: true 

handlers: 
- url: /.* 
    script: helloworld.app 

我沒有寫這些。這些是在谷歌應用程序引擎網站給出的。

我嘗試了兩種不同的方法來運行它。

  1. 其中兩個文件夾中使用終端 :

我用這個命令:dev_appserver.py。 ,這就是我得到:

INFO  2016-04-02 04:28:02,071 sdk_update_checker.py:229] Checking for updates to the SDK. 
INFO  2016-04-02 04:28:02,949 sdk_update_checker.py:257] The SDK is up to date. 
INFO  2016-04-02 04:28:02,982 api_server.py:205] Starting API server at: http://localhost:50345 
INFO  2016-04-02 04:28:02,988 dispatcher.py:197] Starting module "default" running at: http://localhost:8080 
INFO  2016-04-02 04:28:02,989 admin_server.py:116] Starting admin server at: http://localhost:8000 

,當我在Chrome中輸入「http://localhost:8000」,我得到這個錯誤信息: 「localhost的頁面不工作 本地主機是目前無法處理此請求。 「

,這是錯誤味精我得到的終端

ERROR 2016-04-02 04:43:47,109 wsgi.py:263] 
Traceback (most recent call last): 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle 
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler 
    handler, path, err = LoadObject(self._handler) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject 
    obj = __import__(path[0]) 
ImportError: No module named helloworld 
INFO  2016-04-02 04:43:47,114 module.py:787] default: "GET/HTTP/1.1" 500 - 
ERROR 2016-04-02 04:43:47,602 wsgi.py:263] 
Traceback (most recent call last): 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle 
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler 
    handler, path, err = LoadObject(self._handler) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject 
    obj = __import__(path[0]) 
ImportError: No module named helloworld 
INFO  2016-04-02 04:43:47,606 module.py:787] default: "GET/HTTP/1.1" 500 - 
  • 使用谷歌應用程序引擎啓動 我創建了一個新的應用程序,這給了我我需要的所有文件。 所以我就跑了。 它顯示我一個端口號,當我試圖在鉻上, 「http://localhost:8000」 我得到與第一個味精相同的錯誤。
  • 這是什麼,我做錯了? 謝謝。

    +0

    你有沒有試過http:// localhost:8080? – Ook

    +0

    @Ook是的,我已經嘗試過,並沒有奏效。 – Nayana

    回答

    1

    您遇到的問題是您已經命名模塊main.py,但告訴GAE服務器尋找名爲helloworld的模塊。該模塊不存在,所以該網站無法加載。

    無論您main.py文件重命名爲helloworld.py,或更改app.yaml指向main.app而不是helloworld.app

    +0

    非常感謝。這是問題所在。 – Nayana

    +0

    你碰巧知道這個命令:「dev_appserver.py -p 8888」。根據教程,它說「-p」是運行在不同的端口上,但是當我嘗試這個時,我得到這個編譯錯誤消息:「dev_appserver.py:錯誤:無法識別的參數:-p」我該怎麼辦? – Nayana

    +2

    通過使用Google找到的[documentation page](https://cloud.google.com/appengine/docs/python/tools/devserver)表明使用'--port = 8888'而不是'-p 8888'。也許你的教程已過時? – Blckknght

    -2

    webapp2沒有很好的介紹。如果你對web框架還不熟悉,我會建議你從這個開始。

    https://github.com/iogf/untwisted

    它是已建立並實施的一個是微型的web框架,其設計類似於瓶,但要快得多一組插件的事件驅動庫。

    +0

    有什麼辦法可以使它與webapp2一起工作? – Nayana

    +0

    它可能是一個很好的框架,但由於它的設計,它是完全不適合傳統的appengine –

    +0

    是的。我認爲這是可行的。爲什麼你認爲它不是傳統的appengine? –