上代码
from flask import Flask,render_template,request,make_response
from flask_cors import CORS,cross_origin
import requests
import urllib
app = Flask(__name__,)
CORS(app, resources=r'/*')
@app.route('/')
def hello_world():
return "hello world"
@app.route('/image',methods=['GET', 'OPTIONS'])
@cross_origin()
def image():
word = request.args['word']
url = "https://www.jiuwa.net/tools/jupai/index.php"
resp = requests.post(url, data={"t": word})
my_url = f'https://www.jiuwa.net/{resp.content.decode("utf-8")}'
image_data = urllib.request.urlopen(my_url).read()
res = make_response(image_data)
res.headers['Content-Type'] = 'image/png'
return res
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=9999)
结果如下: