本文介绍了Windows 10 IIS URL错误-Python Flask Rest API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的示例python rest API应用程序.我已经在Windows 10 IIS上托管了该应用程序.

This is my sample python rest API application. I have hosted this application on Windows 10 IIS.

hello.py

from flask import Flask
app=Flask(__name__)

@app.route('/',methods=['GET'])
def index():
    return "Hello World 0.0!"

@app.route('/1',methods=['GET'])
def index1():
    return "Hello 1.0!"

@app.route('/2',methods=['GET'])
def index2():
    return "Hello 2.0!"

if __name__=='__main__':
    app.run(debug=True)

web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="FlaskFastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Program Files\Python39\python.exe|&quot;C:\Program Files\Python39\lib\site-packages\wfastcgi.py&quot;" resourceType="Either" requireAccess="Script" />
    </handlers>
    <security>
        <requestFiltering allowDoubleEscaping="true"></requestFiltering>
    </security>
  </system.webServer>

  <appSettings>
    <!-- Required settings -->
    <add key="WSGI_HANDLER" value="hello.app" />
    <add key="PYTHONPATH" value="~/" />

    <!-- Optional settings -->
    <add key="WSGI_LOG" value="C:\website\oboeqa_web.log" />
    <add key="WSGI_RESTART_FILE_REGEX" value=".*((\.py)|(\.config))$" />
  </appSettings>
</configuration>

http://localhost:8080

Hello World 0.0!

http://localhost:8080/1

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

http://localhost:8080/2

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

http://localhost:8080/3

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

仅第一条路线有效,其余路线无效.

The first route only works and the remaining route not working.

推荐答案

您需要修改resourceType:

You need to modify the resourceType:

    <handlers>
      <add name="FlaskFastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python27\python.exe|C:\Python27\lib\site-packages\wfastcgi.pyc" resourceType="Unspecified" requireAccess="Script" />
    </handlers>

您需要将resourceType的值修改为Unspecified.

You need to modify the value of resourceType to Unspecified.

这篇关于Windows 10 IIS URL错误-Python Flask Rest API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 09:54