Streaming chunk of text python/flask in IIS

Hi all,
My app successfully streams answers from my assistant to the browser when I run the flask app directly using py app.py. I’m using iiS to deploy to my intranet an while its all working, it no longer streams the chunks, it just shows the completed answer at the end. I can see the chunks in the event stream in console and the content type is text/event-stream for them. so I’m puzzled to say the least! Our intranet delivered using iis so

My web.config file is below, but, I’ve tried tweaking it various ways without any luck, turned off any caching I can find in iis as well. Any suggestions very much appreciated, as without streaming the chat feels VERY slow to respond.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="PYTHONPATH" value="C:\python\fusion" />
    <add key="WSGI_HANDLER" value="app.app" />
    <add key="WSGI_LOG" value="C:\python\fusion\wfastcgi.log" />
  </appSettings>

  <system.webServer>
    <handlers>
      <add name="Flask" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Users\somewhere\AppData\Local\Programs\Python\Python311\python.exe|C:\Users\somewhere\AppData\Local\Programs\Python\Python311\Lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
    </handlers>
     <httpProtocol>
      <customHeaders>
        <add name="Cache-Control" value="no-cache" />
	<add name="X-Accel-Buffering" value="no" />
      </customHeaders>
    </httpProtocol>
    <staticContent>
      <clientCache cacheControlMode="DisableCache" />
	<remove fileExtension=".pdf" />
            <mimeMap fileExtension=".pdf" mimeType="application/pdf" />
    </staticContent>
        <caching enabled="false" enableKernelCache="false" />

               
  </system.webServer>
</configuration>



Hi, you found any solution for this? Stuck on the exact same issue.

no, I had to move my solution outside to pythonanywhere.com in the end as I couldn’t figure it out.
Buffering | PythonAnywhere help
There’s some info there that might be relevant to the iis issue as well, as I had to do that to get it to work on PythonAnywhere successfully. But I still couldn’t get it to work even with that. Would love to hear if anyone else has had any luck!

What I did is I just ran the flask on host 0.0.0.0. Then it was on a public IP, so my API from another server would make a call to the public IP that straight away.

I also face this problem, and it should not only on FastAPI and also on other
Python web library such as Django and Flask. As HttpPlatformHandler has 8kb output buffer, so the message is not sent out immediately. I see some people say using ASP NET to run the Python / FastAPI on IIS but sadly I can’t make it work, so I dive into stackoverflow and find out this.(lextudio->httpplatformhandlerv2), I cant post link, so search it in GitHub.
It seem a team has update the httpPlatform handler and this open source one does support stream response and u do not need to write any extra stuff. But there is warning from Windows say this is not safe to install the msi file. I tried and yes its work but I dont know will my server got hacked lol.
After installation, scroll down the GitHub page, u can see a link to the author’s blog, u may find the tur on how to setup on IIS. (Why i cant send link lol)