【发布时间】:2016-10-16 20:15:38
【问题描述】:
我在 Google Appengine 中创建了一个新项目,但是当我尝试通过 localhost 访问它时,我收到了 HTTP 500 错误。我的浏览器显示“本地主机当前无法处理此请求。”以下是我的新项目代码:
app.yaml:
application: hello-world
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"
main.py:
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello world!')
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
当我在命令行上运行以下命令时:
python "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py" "C:\Users\Jason\Desktop\Hello World\hello-world"
我得到了错误
import webapp2
ImportError: No module named webapp2
INFO 2016-06-18 15:29:37,092 module.py:788] default: "GET / HTTP/1.1" 500 -
【问题讨论】:
-
您是否运行了 dev-appserver?如果是,它在哪个端口上运行?你请求的是什么 localhost url?
-
是的,我尝试运行 dev-appserver,但出现以下错误:import webapp2 ImportError: No module named webapp2 我正在使用端口 8080,url 是 localhost:8080。
-
我建议尝试两件事。首先,尝试通过应用引擎而不是命令行运行程序。其次,您可能想尝试安装和使用 Python 2.7 而不是 2.5。
-
@coralv 我尝试通过应用程序引擎和命令行运行。我也安装了 Python 2.7 而不是 2.5。我的代码是否有其他错误?
-
什么是错误日志? 500 应该在控制台中有错误日志,假设请求由开发应用服务器提供服务。
标签: python google-app-engine web-development-server