Quantcast
Viewing all articles
Browse latest Browse all 14011

Python return image to http request

I setup python in iis with handler "c:...\python.exe %s %s" for *.py. Then want to provide url like "https://.../getpng.py?no=1" to return image stream to html as below

<img src="https://.../getpng.py?no=1">

The getpng.py is simple as below.

with open('C:\\inetpub\\wwwroot\\test\\test1.png', 'rb') as f:    filecontent = f.read()print('Content-Type: image/png\r\n\r\n')print(filecontent )

The image path is correct. The filecontent is correct. But html page always shows broken image.It looks like "print(filecontent)" failed. Any hints to solve this issue?

I tried sys.stdout.write but that did not work neither.

Also tried the following neither workingprint('Content-Type: image/png\r\n\r\n'+ filecontent )print('Content-Type: image/png\r\n\r\n{0}'.format(filecontent ))


Viewing all articles
Browse latest Browse all 14011

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>