Joy 宇 2023-01-18 14:58 采纳率: 77.8%
浏览 33
已结题

(Flask,python) OSError: [Errno 50] Protocol not available

Q: 如何结合html和python flask
我的目标是使现有网站能(用flask)在网址取值

  • html 代码
<script type=module src=main_joy_01_12.js></script><my-header></my-header>

<head>
    <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
    <script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>

<html>
    <p>fix title/contaxt</p>
    <h1>this is the data extract from mysql: Nordic85678</h1>
    </body>
</html>



<py-config>
    packages = ["flask"]
</py-config>

<py-script>

    # pyscript 这里能在 html 使用python
    # 以下为普通的 python 代码, 单独跑python脚本没问题
    from flask import Flask, request
    
    # create the Flask app
    app = Flask(__name__)
    
    
    @app.route('/data')
    def query_example():
        # if key doesn't exist, returns None
        P_ID = request.args.get('P_ID')
    
        # if key doesn't exist, returns None
        P_TITLE = request.args.get('P_TITLE')
    
        return ''' 
    
                <script type=module src=main_joy_01_12.js></script><my-header></my-header>
    
    <head>
        <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
        <script defer src="https://pyscript.net/latest/pyscript.js"></script>
    </head>
    
    <html>
        <p>fix title/contaxt</p>
        <h1>this is the data extract from mysql: {}</h1>
    
        </body>
    </html>
    
    
    '''.format( P_TITLE)
    
                
    if __name__ == '__main__':
        # run app in debug mode on port 5000
        app.run(debug=True, port=5000)
    
</py-script>

<my-footer></my-footer>
  • 报错
Traceback (most recent call last):
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 435, in eval_code
    .run(globals, locals)
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 304, in run
    coroutine = eval(self.code, globals, locals)
  File "<exec>", line 235, in <module>
  File "/lib/python3.10/site-packages/flask/app.py", line 1188, in run
    run_simple(t.cast(str, host), port, self, **options)
  File "/lib/python3.10/site-packages/werkzeug/serving.py", line 1062, in run_simple
    s = prepare_socket(hostname, port)
  File "/lib/python3.10/site-packages/werkzeug/serving.py", line 898, in prepare_socket
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
OSError: [Errno 50] Protocol not available
  • 网页呈现

    https://ithelp.ithome.com.tw/upload/images/20230118/20153034IjNFVICwSS.png

https://ithelp.ithome.com.tw/upload/images/20230118/20153034VfD6iEytEt.png

要如何修复报错,感谢

  • 写回答

2条回答 默认 最新

  • Halifax ‎ 2023-01-18 18:22
    关注

    错误最后一行,提示:协议不可用,python 网络不起作用

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 2月6日
  • 已采纳回答 2月6日
  • 创建了问题 1月18日

悬赏问题

  • ¥20 R语言单细胞测序 对seurat对象进行标准化时出现问题
  • ¥15 Anaconda navigator updateor一直更新
  • ¥15 请问如何在matlab里使用raven工具?
  • ¥100 关于ios手游充值到一定金额,再点充值提示公众号的问题。
  • ¥15 求一个stm32串口控制程序
  • ¥20 Windows 驱动开发版本疑问相关
  • ¥15 MAC 未能打开磁盘映像
  • ¥15 fastcap使用,二维导体输入问题
  • ¥15 hosts修改后不能访问
  • ¥15 关于化学反应速率C++编译问题/FLUENT