这段代码有什么bug
main.py
import requests, json
from flask import Flask, session, make_response, redirect, url_for
app = Flask(__name__)
with open('web/jpg/1.jpg', 'rb') as f:
img = f.read()
result = requests.post('http://127.0.0.1:24401/', params={'threshold': 0.1},
data=img).json()
print(result["results"][0]["confidence"])
global traceback
# 全局化
traceback = result["results"][0]["confidence"]
# 变量赋值
#路径定义,方便单片机B接收
@app.route('/', methods=['GET', 'POST'])
def data_handler(confidence) :
r = make_response('Accomplished
')
r.set_cookie('confidence', traceback)
return json.dumps({'confidence': traceback})
#转化为Python字典
app.run(port= 80, debug=True)
#port端口号 默认于127.0.0.1运行
client.py
import threading
import urllib.request, requests
handler_url = 'http://......'
#此处为main.py中的ip地址+main.py中/data/api/handle路径
class check_data(threading.Thread) :
def __init__(self, confidence) :
threading.Thread.__init__(self)
self.event = threading.Event()
self.confidence = confidence
def run(self) :
global handler_url
try :
while not self.event.is_set() :
r = requests.get(handler_url)
Specimen = r.cookies['confidence']
print(Specimen)
except :
pass
self.event.wait(1)
#()可以更改即更改间隔时间