下载文件遇到500

书山人海 发表于2020年03月02日
HTTP Error 500:INTERNAL SERVER ERROR 代码如下: 服务端 import flaskimport osapp=flask.Flask(__name__)@app.route("/") def index(): if "fileName" not in flask.request.values: return "图像.jpg" else: data=b"" try: fileName=flask.request.values.get("fileName") if fileName !="" and os.path.exists(fileName): fobj=open(fileName,"rb") data=fobj.read() fobj.close() except Exception as err: data=str(err).encode() return data if __name__ =="__main__": app.run() 客户端 import urllib.request import urllib.parse url="https://127.0.0.1:5000" try: html=urllib.request.urlopen(url) html=html.read() fileName=html.decode() print("准备下载"+fileName) urllib.request.urlretrieve(url+"?fileName="+urllib.parse.quote(fileName),"download"+fileName) print("下载完毕",len(data),"字节") except Exception as err: print(err) 有遇到的大神,可以帮忙分析一下原因吗