【发布时间】:2020-06-16 08:23:38
【问题描述】:
我在 ec2.(amazon linux2) 上尝试了下面的代码
from sanic import Sanic
from sanic.response import json
app = Sanic()
@app.route('/')
async def test(request):
return json({'hello': 'world'})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)
运行良好。
当我将端口号更改为 80 时,如下所示
from sanic import Sanic
from sanic.response import json
app = Sanic()
@app.route('/')
async def test(request):
return json({'hello': 'world'})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)
系统回复,
main.py:4: DeprecationWarning: Sanic(name=None) is deprecated and None value support for `name` will be removed in the next release. Please use Sanic(name=‘your_application_name’) instead.
app = Sanic()
[2020-06-16 08:16:15 +0000] [8303] [INFO] Goin’ Fast @ http://0.0.0.0:80
[2020-06-16 08:16:15 +0000] [8303] [ERROR] Unable to start server
Traceback (most recent call last):
File “/home/ec2-user/sanic/lib64/python3.7/site-packages/sanic/server.py”, line 835, in serve
http_server = loop.run_until_complete(server_coroutine)
File “uvloop/loop.pyx”, line 1456, in uvloop.loop.Loop.run_until_complete
File “uvloop/loop.pyx”, line 1727, in create_server
PermissionError: [Errno 13] error while attempting to bind on address (‘0.0.0.0’, 80): permission denied
[2020-06-16 08:16:15 +0000] [8303] [INFO] Server Stopped
所以接下来我做了
sudo python main.py
然后错误消息说,
File “main.py”, line 7
async def test(request):
^
SyntaxError: invalid syntax
我不知道该怎么办。 给我一些建议。
我的文件夹如下所示
sanic/
├ bin/
├ includs/
├ lib/
├ lib64
├ main.py
└ pyvenv.cfg
【问题讨论】: