开发者社区> 问答> 正文

python遇到 [WinError 10049] 在其上下文中,该请求的地址无效的问题。

源码1.py

from flask import Flask
app=Flask(__name__)

@app.route("/")
def index():
    return "{a:1,b:2}"

app.run(host='139.....',port=4444)

139.....是阿里ECS的公网IP

cmd python 1.py的报错信息

Microsoft Windows [版本 6.3.9600]
(c) 2013 Microsoft Corporation。保留所有权利。
C:\Users\Administrator>cd C:\Users\Administrator\Desktop\back
C:\Users\Administrator\Desktop\back>python 1.py
 * Serving Flask app "1" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployme
nt.
   Use a production WSGI server instead.
 * Debug mode: off
Traceback (most recent call last):
  File "1.py", line 8, in <module>
    app.run(host='139.196.31.15',port=4444)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-p
ackages\flask\app.py", line 990, in run
    run_simple(host, port, self, **options)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-p
ackages\werkzeug\serving.py", line 1052, in run_simple
    inner()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-p
ackages\werkzeug\serving.py", line 996, in inner
    srv = make_server(
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-p
ackages\werkzeug\serving.py", line 847, in make_server
    return ThreadedWSGIServer(
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-p
ackages\werkzeug\serving.py", line 740, in __init__
    HTTPServer.__init__(self, server_address, handler)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\socket
server.py", line 452, in __init__
    self.server_bind()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\http\s
erver.py", line 138, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\socket
server.py", line 466, in server_bind
    self.socket.bind(self.server_address)
OSError: [WinError 10049] 在其上下文中,该请求的地址无效。

改成app(host='localhost',port=4444)之后ECS服务器上访问http://localhost:4444可以正常获取

计划用pymysql和flask来交互传输前端数据,想问问是什么错误。。

展开
收起
游客xdwx6l6thhfxa 2020-06-08 16:34:42 6531 0
1 条回答
写回答
取消 提交回答
  • netstat -ano|findstr "4444" 看下你本机是否有其他的服务占用了4444端口导致socket bind失败

    2020-09-20 17:15:45
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载