8

我正在用 python 尝试“Hello world”

  import webapp2

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.response.write('Hello world!')

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

应用程序.yaml

application: engineapp
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: .*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.2"

但是在 Google App Launcher 中运行时会出现此错误

INFO     2013-05-22 12:22:40,302 admin_server.py:117] Starting admin server at: xxxxx:8000
HTTPError()
HTTPError()
Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_app_engine\lib\cherrypy\cherrypy\wsgiserver\wsgiserver2.py", line 1302, in communicate
    req.respond()
  File "C:\Program Files (x86)\Google\google_app_engine\lib\cherrypy\cherrypy\wsgiserver\wsgiserver2.py", line 831, in respond
    self.server.gateway(self).respond()
  File "C:\Program Files (x86)\Google\google_app_engine\lib\cherrypy\cherrypy\wsgiserver\wsgiserver2.py", line 2115, in respond
    response = self.req.server.wsgi_app(self.env, self.start_response)
  File "C:\Program Files (x86)\Google\google_app_engine\google\appengine\tools\devappserver2\wsgi_server.py", line 246, in __call__
    return app(environ, start_response)
  File "C:\Program Files (x86)\Google\google_app_engine\google\appengine\tools\devappserver2\request_rewriter.py", line 311, in _rewriter_middleware
    response_body = iter(application(environ, wrapped_start_response))
  File "C:\Program Files (x86)\Google\google_app_engine\google\appengine\tools\devappserver2\python\request_handler.py", line 89, in __call__
    self._flush_logs(response.get('logs', []))
  File "C:\Program Files (x86)\Google\google_app_engine\google\appengine\tools\devappserver2\python\request_handler.py", line 220, in _flush_logs
    apiproxy_stub_map.MakeSyncCall('logservice', 'Flush', request, response)
  File "C:\Program Files (x86)\Google\google_app_engine\google\appengine\api\apiproxy_stub_map.py", line 94, in MakeSyncCall
    return stubmap.MakeSyncCall(service, call, request, response)
  File "C:\Program Files (x86)\Google\google_app_engine\google\appengine\api\apiproxy_stub_map.py", line 320, in MakeSyncCall
    rpc.CheckSuccess()
  File "C:\Program Files (x86)\Google\google_app_engine\google\appengine\api\apiproxy_rpc.py", line 156, in _WaitImpl
    self.request, self.response)
  File "C:\Program Files (x86)\Google\google_app_engine\google\appengine\ext\remote_api\remote_api_stub.py", line 200, in MakeSyncCall
    self._MakeRealSyncCall(service, call, request, response)
  File "C:\Program Files (x86)\Google\google_app_engine\google\appengine\ext\remote_api\remote_api_stub.py", line 226, in _MakeRealSyncCall
    encoded_response = self._server.Send(self._path, encoded_request)
  File "C:\Program Files (x86)\Google\google_app_engine\google\appengine\tools\appengine_rpc.py", line 393, in Send
    f = self.opener.open(req)
  File "C:\Python27\lib\urllib2.py", line 410, in open
    response = meth(req, response)
  File "C:\Python27\lib\urllib2.py", line 523, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Python27\lib\urllib2.py", line 448, in error
    return self._call_chain(*args)
  File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "C:\Python27\lib\urllib2.py", line 531, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 503: Service Unavailable

我更改 GAE Launcher(1.7.7) 版本并重新安装 python 但不起作用

我正在使用 Windows 7、python 2.7 和 EAG Launcher 1.8.0

4

3 回答 3

22

在代理服务器后面使用 Google App Engine Launcher 1.8.6 的代理服务器时,我的 MacOSX 也遇到了同样的问题。显然,“urllib2.py”上的“proxy_bypass”存在问题。

有两种可能的解决方案:

  1. 降级到 1.7.5,但是,谁想降级?
  2. 编辑“[GAE 安装路径]/google/appengine/tools/appengine_rpc.py”并查找显示的行

    opener.add_handler(fancy_urllib.FancyProxyHandler())

在我的计算机中是第 578 行,然后在行首放一个井号 (#),如下所示:

`#opener.add_handler(fancy_urllib.FancyProxyHandler())`

保存文件,停止然后重新启动您的应用程序。现在 dev_appserver.py 根本不应该尝试使用任何代理服务器。

如果您的应用程序使用任何外部资源,例如 SOAP Web 服务或类似的东西,并且您无法在没有代理服务器的情况下访问服务器,那么您将不得不降级。请记住,外部 javascript 文件(如 facebook SDK 或类似文件)是从您的浏览器加载的,而不是从您的应用程序加载的。

因为我没有使用任何外部 REST 或 SOAP 服务,所以它对我有用!

希望它也对你有用。

于 2013-10-18T22:42:58.680 回答
1

我的解决方案是通过以下方式删除所有代理设置:
unset http_proxy https_proxy ftp_proxy ftps_proxy

然后通过重启应用程序
dev_appserver.py helloworld/

如果你在windows下,那么你必须改变IE配置的“Internet选项”。

于 2014-02-18T11:53:45.947 回答
-2

您可能想尝试从命令行运行您的应用程序。跑

dev_appserver.py --port=8080 myapp

从您的应用程序的目录中,并将“myapp”替换为您的应用程序的名称。

更多信息可以在 GAE 文档中找到: https ://developers.google.com/appengine/docs/python/tools/devserver#Running_the_Development_Web_Server

于 2013-07-08T08:29:01.743 回答