首页 > 程序开发 > Web开发 > Python >

Python廖雪峰实战web开发(Day2-编写Web APP骨架) -- 500 Internal Server Error Server got itself in trouble

2017-07-03

Python廖雪峰实战web开发(Day2-编写Web APP骨架) -- 500 Internal Server Error Server got itself in trouble。

Python廖雪峰实战web开发(Day2-编写Web APP骨架) -- 500 Internal Server Error Server got itself in trouble。

# app.py

import logging; logging.basicConfig(level=logging.INFO)

import asyncio, os, json, time
from datetime import datetime

from aiohttp import web

def index(request):
	return web.Respnse(body=b'

Hello,wolrd. I 'm Henry.

', content_type='text/html') @asyncio.coroutine def init(loop): app = web.Application(loop=loop) app.router.add_route('GET', '/', index) srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000) logging.info('server started at http://127.0.0.1:9000...') return srv loop = asyncio.get_event_loop() loop.run_until_complete(init(loop)) loop.run_forever()
Linux命令行中输入:

$ python3 app.py

浏览器报错:

【500 Internal Server Error
Server got itself in trouble】

命令行的全部报错信息:

$ python3 app.py 
INFO:root:server started at http://127.0.0.1:9000...
ERROR:aiohttp.server:Error handling request
Traceback (most recent call last):
  File "/home/henry/.local/lib/python3.5/site-packages/aiohttp/web_protocol.py", line 422, in start
    resp = yield from self._request_handler(request)
  File "/home/henry/.local/lib/python3.5/site-packages/aiohttp/web.py", line 306, in _handle
    resp = yield from handler(request)
  File "/home/henry/.local/lib/python3.5/site-packages/aiohttp/web_urldispatcher.py", line 113, in handler_wrapper
    result = old_handler(*args, **kwargs)
  File "app.py", line 11, in index
    return web.Respnse(body=b'

Hello,wolrd. I 'm Henry.

', content_type='text/html') AttributeError: module 'aiohttp.web' has no attribute 'Respnse' INFO:aiohttp.access:127.0.0.1 - - [02/Jul/2017:09:05:53 +0000] "GET / HTTP/1.1" 500 330 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0"

注意到:

AttributeError: module 'aiohttp.web' has no attribute 'Respnse'

原来是Respnse拼写错误,修改为Response后,重新保存app.py,并python3 app.py,打开浏览器查看,网页正常显示。

相关文章
最新文章
热点推荐