我正在尝试使用XAMPP(apache)-Webserver在Web浏览器中显示.JPG文件。 Python 3.4 / Windows 8.1
HTML文件包含指向(python)-cgi文件的链接:
<form action="/xampp/htdocs/Python34/server_kontakt.cgi">
Python-cgi文件:
#!C:\Python34\python.exe
import cgi, cgitb, sys
def chk(element):
global form
if element in form:
erg = form[element].value
else:
erg = ""
return erg
d = open("log.txt","a")
cgitb.enable()
form = cgi.FieldStorage()
s = str(form)
d.write(s)
d.close()
print("Content-type: text/html")
print()
print("<p>Ihre Daten wurden gesendet</p>")
data_uri = open(r'C:\xampp\cgi-bin\Python34\daten.jpg', 'rb')
.read().encode('base64').replace('\n', '')
print(img_tag)
print("</body>")
print("</html>")
问题是,当我想显示cgi -file时,浏览器只显示python代码 或者有时我收到这条消息:
'bytes' object has no attribute 'encode'