tasks.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. from celery import shared_task
  2. import time
  3. import os
  4. from imutils import paths
  5. import stat
  6. import datetime
  7. import re
  8. import copy
  9. from django.utils.decorators import method_decorator
  10. from django.views.decorators.csrf import csrf_exempt
  11. # import xlrd
  12. from apps.SimInfo.views import get_siminfo
  13. import requests
  14. from io import BytesIO
  15. import sys
  16. from PIL import Image
  17. import argparse
  18. import cv2
  19. import shutil
  20. import glob
  21. from apps.AppInfoManage.models import Equip, User_Log, MyUser,Equip_Forward
  22. from apps.AppInfoManage.models import SCDdata, SCDstatus, RecentSCDdata, YBQdata, YBQstatus, QXZstatus, QXZdata, Trapstatus, Trapdata, Trapphoto, Equip_SimInfo
  23. from apps.AppInfoManage.models import CBDstatus, CBDdata, CBDphoto, CBDpest, CBDphoto_desc, YBQphoto, BZYstatus, BZYdata, BZYphoto, Spore_Exist, QXZswitchstatus, QXZswitchdata,\
  24. RecentCBDdata, QXZTimingswitch, QXZAutoswitch, Msg_Conf
  25. import json
  26. import time
  27. import paho.mqtt.client as mqtt
  28. from apps.EquipManage.views import CJSONEncoder
  29. # 复制
  30. def mycopyfile(srcfile,dstfile):
  31. if not os.path.isfile(srcfile):
  32. print("%s not exist!"%(srcfile))
  33. else:
  34. fpath,fname=os.path.split(dstfile) #分离文件名和路径
  35. if not os.path.exists(fpath):
  36. os.makedirs(fpath) #创建路径
  37. shutil.copyfile(srcfile,dstfile) #复制文件
  38. print("copy %s -> %s"%(srcfile,dstfile))
  39. def mkdir(path):
  40. # 去除首位空格
  41. path=path.strip()
  42. # 去除尾部 \ 符号
  43. path=path.rstrip("\\")
  44. # 判断路径是否存在
  45. # 存在 True
  46. # 不存在 False
  47. isExists=os.path.exists(path)
  48. # 判断结果
  49. if not isExists:
  50. # 如果不存在则创建目录
  51. # 创建目录操作函数
  52. os.makedirs(path)
  53. print(path+' 创建成功')
  54. return True
  55. else:
  56. # 如果目录存在则不创建,并提示目录已存在
  57. print(path+' 目录已存在')
  58. return False
  59. def variance_of_laplacian(image):
  60. # 拉普拉斯的方差
  61. return cv2.Laplacian(image, cv2.CV_64F).var()
  62. @shared_task
  63. def photo_transpond(imei,a_path,a_name):
  64. # FTP转发图片
  65. nowtime = datetime.datetime.now().strftime('%Y%m%d')
  66. origin = sys.stdout
  67. mkdir('logs/%s'%imei)
  68. f = open('logs/%s/'%imei + nowtime +'.txt','a')
  69. sys.stdout = f
  70. img_addr = "pyftp/" + os.path.join(a_path, a_name)
  71. try:
  72. # if imei == "868575028869008":
  73. #丁艳青 云洋 更换设备号
  74. if imei == "869300039229913" or imei == "860344048751540":
  75. # if imei == "868956044831497" or imei == "865650043175898":
  76. print("img_addr",img_addr)
  77. time.sleep(20)
  78. a = "/data/yfwlw/" + img_addr
  79. # a = "/home/web/yfwlw/" + img_addr
  80. # c = event.name
  81. # b = c.replace(':','-')
  82. # 切割文件名
  83. # aa = img_addr.split("/")
  84. # 拼接文件夹
  85. # b = aa[3] + "/" + aa[4] + "/" + b
  86. n_time = datetime.datetime.now()
  87. b = imei + "/" + n_time.strftime('%Y%m%d') + "/" + n_time.strftime('%H-%M-%S') + ".jpg"
  88. # print("bbbbbbb",b)
  89. print("target_ftp_name:",b)
  90. ftp_url = os.system(r'curl ftp://47.95.247.86:8022/%s --ftp-create-dirs -u "hnyfkj:hnyfkj19416" -T "%s" -# -v'%(b,a))
  91. print("=====>>",ftp_url)
  92. else:
  93. pass
  94. if imei == "869300039255967" or imei == "869300039253798" or imei == "868575028876029":
  95. print("img_addr",img_addr)
  96. time.sleep(20)
  97. a = "/data/yfwlw/" + img_addr
  98. # a = "/home/web/yfwlw/" + img_addr
  99. # c = event.name
  100. # b = c.replace(':','-')
  101. # 切割文件名
  102. # aa = img_addr.split("/")
  103. # 拼接文件夹
  104. # b = aa[3] + "/" + aa[4] + "/" + b
  105. n_time = datetime.datetime.now()
  106. b = imei + "/" + n_time.strftime('%Y%m%d') + "/" + n_time.strftime('%H-%M-%S') + ".jpg"
  107. print("target_ftp_name:",b)
  108. ftp_url = os.system(r'curl ftp://47.95.247.86:8022/%s --ftp-create-dirs -u "xjhnyfkj:xjhnyfkj511" -T "%s" -# -v'%(b,a))
  109. print("=====>>",ftp_url)
  110. else:
  111. pass
  112. except Exception as eee:
  113. print(eee)
  114. try:
  115. time.sleep(10)
  116. # insect_indentify 昆虫识别
  117. # # 保存图片之后调用害虫识别接口
  118. # 正则切割文件名 去掉.jpg后缀
  119. a_name = a_name.replace(".jpg","")
  120. # pattern = r'[.]'
  121. # res = a_name
  122. # result = re.split(pattern, res)
  123. # insect_pic_name = result[0] + 'result' + '.jpg'
  124. insect_pic_name = a_name + 'result' + '.jpg'
  125. # url = 'http://60.166.14.184:9143/upload'
  126. url = 'http://60.166.14.184:9143/upload'
  127. # 测试服务器路径
  128. # imageFile = {'imageFile':('pic.jpg',open("/home/web/yfwlw/" + img_addr,'rb'),'image/jpeg')}
  129. lng = CBDstatus.objects.get(equip_id=imei).lng
  130. lat = CBDstatus.objects.get(equip_id=imei).lat
  131. # 正式服务器路径
  132. imageFile = {'imageFile':('pic.jpg',open("/data/yfwlw/" + img_addr,'rb'),'image/jpeg')}
  133. data = {'longitude':lng,'latitude':lat}
  134. print('data:',data)
  135. res = requests.post(url,data=data,files=imageFile,timeout=10)
  136. print("res:",res.text)
  137. resp = json.loads(res.text)
  138. print("insect_pic_name:", insect_pic_name)
  139. print("-------------------------接口调用成功")
  140. except Exception as e:
  141. print(e)
  142. print("---------------------识别失败")
  143. try:
  144. if resp["returnResult"]["returnStatus"] == "0":
  145. print("识别结果为空,不进行保存")
  146. else:
  147. # 将识别结果中的链接中的图片存入本地 测试服务器
  148. # pic_dir_1 = "/home/web/yfwlw/result_pyftp/" + a_path + "/"
  149. pic_dir_1 = "/data/yfwlw/result_pyftp/" + a_path + "/"
  150. print("pic_dir_1:",pic_dir_1)
  151. if os.path.exists(pic_dir_1) == False:
  152. os.makedirs(pic_dir_1)
  153. img_src = resp["returnResult"]["returnImageUrl"]
  154. response = requests.get(img_src)
  155. image = Image.open(BytesIO(response.content))
  156. insect_image_addr = pic_dir_1 + insect_pic_name
  157. print("insect_image_addr:",insect_image_addr)
  158. image.save(insect_image_addr)
  159. print("------------------图片保存成功")
  160. try:
  161. photo_obj = CBDphoto.objects.get(addr=img_addr)
  162. if resp["returnResult"]["returnStatus"] == "0":
  163. print("识别结果为空,不进行保存")
  164. else:
  165. # 将识别结果存入数据库
  166. pic_dir = "result_pyftp/" + os.path.join(a_path, insect_pic_name)
  167. photo_obj.indentify_photo = pic_dir
  168. photo_obj.indentify_result = resp["returnResult"]["returnString"]
  169. photo_obj.save()
  170. print("图片路径:", pic_dir)
  171. print("---------------数据库保存识别结果成功")
  172. except Exception as ex:
  173. print(ex)
  174. print("---------------数据库保存识别结果失败")
  175. except Exception as exc:
  176. print(exc)
  177. print("----------------识别结果图片保存失败")
  178. try:
  179. if imei == "868956044807455" or imei == "868956044806671" or imei == "868956044831604" or imei == "868956044831711" or imei == "868956044807471" or imei == "868956044830994" or imei == "868956044824930" or imei == "868956044807455" or imei == "865650043209341" or imei == "868956044806705" or imei == "868956044830929" or imei == "868956044824898" or imei == "868956044830887" or imei == "868956044830911":
  180. try:
  181. if CBDphoto.objects.get(addr=img_addr).indentify_photo == None:
  182. indentify_photo_1 = ""
  183. indentify_result_1 = ""
  184. img_addr_1 = "http://120.27.222.26/" + img_addr
  185. else:
  186. r_photo = CBDphoto.objects.get(addr=img_addr).indentify_photo
  187. indentify_result_1 = CBDphoto.objects.get(addr=img_addr).indentify_result
  188. img_addr_1 = "http://120.27.222.26/" + img_addr
  189. indentify_photo_1 = "http://120.27.222.26/" + r_photo
  190. data = {
  191. "cmd": "Imageresult",
  192. "ext": {
  193. "Image": img_addr_1,
  194. "Result_image": indentify_photo_1,
  195. "Result": indentify_result_1,
  196. "imei": imei
  197. }
  198. }
  199. except Exception as eee:
  200. print("====京东错误信息为",eee)
  201. data = {
  202. "cmd": "Imageresult",
  203. "ext": {
  204. "Image": "",
  205. "Result_image": "",
  206. "Result": "",
  207. "imei": imei
  208. }
  209. }
  210. TASK_TOPIC = '/yfkj/cbd/sub/%s'%imei # 客户端发布消息主题
  211. """
  212. 客户端发布消息
  213. :param message: 消息主体
  214. :return:
  215. """
  216. payload = data
  217. # publish(主题:Topic; 消息内容)
  218. client_id = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
  219. client = mqtt.Client(client_id, transport='tcp')
  220. client.connect("120.27.222.26", 1883, 60) # 此处端口默认为1883,通信端口期keepalive默认60
  221. client.loop_start()
  222. client.publish(TASK_TOPIC, json.dumps(payload, ensure_ascii=False))
  223. print("京东信息发送成功",data)
  224. # equip = Equip.objects.get(equip_id=imei)
  225. # if equip.ftp_addr:
  226. # # http://120.27.222.26/cbd/pyftp/ftp_file/ykm_cbd/868575028845867/20190305/20:56:15.jpg
  227. # ftp_addr = equip.ftp_addr
  228. # pattern = r'[#]'
  229. # split_result = re.split(pattern, ftp_addr)
  230. # print("split_result:",split_result)
  231. # try:
  232. # need_result = split_result[1]
  233. # except:
  234. # print("对接设备的地址填写有误!请检查!")
  235. # need_result = "0"
  236. print("imei------------------------>>",imei)
  237. try:
  238. equip_list = Equip_Forward.objects.get(equip_id=imei)
  239. ftp_addr = equip_list.equip_img_url
  240. pattern = r'[#]'
  241. split_result = re.split(pattern, ftp_addr)
  242. print("split_result:",split_result)
  243. need_result = split_result[1]
  244. except:
  245. print("对接设备的地址填写有误!请检查!")
  246. need_result = "400"
  247. #害虫识别
  248. if need_result == "1":
  249. if CBDphoto.objects.get(addr=img_addr).indentify_result == None:
  250. indentify_photo_1 = CBDphoto.objects.get(addr=img_addr).indentify_result
  251. else:
  252. r_photo = CBDphoto.objects.get(addr=img_addr).indentify_photo
  253. indentify_photo_1 = "http://120.27.222.26/" + r_photo
  254. try:
  255. # r_photo = CBDphoto.objects.get(addr=img_addr).indentify_photo
  256. indentify_result_1 = CBDphoto.objects.get(addr=img_addr).indentify_result
  257. img_addr_1 = "http://120.27.222.26/" + img_addr
  258. # indentify_photo_1 = "http://120.27.222.26/" + r_photo
  259. print("img_addr_1:",img_addr_1)
  260. print("indentify_photo_1:",indentify_photo_1)
  261. print("indentify_result_1:",indentify_result_1)
  262. if indentify_result_1 == None:
  263. data = {
  264. "Image":img_addr_1,
  265. "imei":imei,
  266. "Result_image":"0",
  267. "Result":"0",
  268. }
  269. else:
  270. data = {
  271. "Image":img_addr_1,
  272. "Result_image":indentify_photo_1,
  273. "Result":indentify_result_1,
  274. "imei":imei
  275. }
  276. data = json.dumps(data, cls=CJSONEncoder)
  277. print("data:",data)
  278. if equip_list.equip_img_between == "1":
  279. res_1 = requests.post(split_result[0],data=data,timeout=2)
  280. elif equip_list.equip_img_between == "2":
  281. headers = {"Content-Type": "application/json; charset=UTF-8", 'Connection': 'close'}
  282. res_1 = requests.post(split_result[0], data=data, timeout=3,headers=headers)
  283. print("res_1:",res_1)
  284. print("------------------识别结果发送成功!!!")
  285. except Exception as aex:
  286. print(aex)
  287. try:
  288. img_addr_1 = "http://120.27.222.26/" + img_addr
  289. print("img_addr_1:",img_addr_1)
  290. data = {
  291. "Image":img_addr_1,
  292. "imei":imei,
  293. "Result_image":"0",
  294. "Result":"0",
  295. }
  296. data = json.dumps(data, cls=CJSONEncoder)
  297. print("data:",data)
  298. print("url:",split_result[0])
  299. if equip_list.equip_img_between == "1":
  300. res_1 = requests.post(split_result[0],data=data,timeout=2)
  301. elif equip_list.equip_img_between == "2":
  302. headers = {"Content-Type": "application/json; charset=UTF-8", 'Connection': 'close'}
  303. res_1 = requests.post(split_result[0], data=data, timeout=3,headers=headers)
  304. print(res_1.text)
  305. except Exception as e:
  306. print("错误信息为",e)
  307. print("------------------识别结果发送失败!!!")
  308. #害虫计数
  309. elif need_result == "2":
  310. try:
  311. # r_photo = CBDphoto.objects.get(addr=img_addr).indentify_photo
  312. indentify_result_1 = CBDphoto.objects.get(addr=img_addr).indentify_result
  313. img_addr_1 = "http://120.27.222.26/" + img_addr
  314. # indentify_photo_1 = "http://120.27.222.26/" + r_photo
  315. print("img_addr_1:",img_addr_1)
  316. print("indentify_result_1:",indentify_result_1)
  317. data = {
  318. "Image":img_addr_1,
  319. "Result":indentify_result_1,
  320. "imei":imei
  321. }
  322. data = json.dumps(data, cls=CJSONEncoder)
  323. print("data:",data)
  324. if equip_list.equip_img_between == "1":
  325. res_1 = requests.post(split_result[0],data=data,timeout=2)
  326. elif equip_list.equip_img_between == "2":
  327. headers = {"Content-Type": "application/json; charset=UTF-8", 'Connection': 'close'}
  328. res_1 = requests.post(split_result[0], data=data, timeout=3,headers=headers)
  329. print("res_1:",res_1)
  330. print("------------------识别结果发送成功!!!")
  331. except Exception as aex:
  332. print(aex)
  333. try:
  334. img_addr_1 = "http://120.27.222.26/" + img_addr
  335. print("img_addr_1:",img_addr_1)
  336. data = {
  337. "Image":img_addr_1,
  338. "imei":imei,
  339. "Result":"0",
  340. }
  341. data = json.dumps(data, cls=CJSONEncoder)
  342. print("data:",data)
  343. print("url:",split_result[0])
  344. if equip_list.equip_img_between == "1":
  345. res_1 = requests.post(split_result[0],data=data,timeout=2)
  346. elif equip_list.equip_img_between == "2":
  347. headers = {"Content-Type": "application/json; charset=UTF-8", 'Connection': 'close'}
  348. res_1 = requests.post(split_result[0], data=data, timeout=3,headers=headers)
  349. print(res_1.text)
  350. except Exception as e:
  351. print("错误信息为",e)
  352. print("------------------识别结果发送失败!!!")
  353. #不带害虫识别
  354. elif need_result == "0":
  355. try:
  356. img_addr_1 = "http://120.27.222.26/" + img_addr
  357. print("img_addr_1:",img_addr_1)
  358. data = {
  359. "Image":img_addr_1,
  360. "imei":imei
  361. }
  362. data = json.dumps(data, cls=CJSONEncoder)
  363. print("data:",data)
  364. print("url:",split_result[0])
  365. if equip_list.equip_img_between == "1":
  366. res_1 = requests.post(split_result[0],data=data,timeout=2)
  367. elif equip_list.equip_img_between == "2":
  368. headers = {"Content-Type": "application/json; charset=UTF-8", 'Connection': 'close'}
  369. res_1 = requests.post(split_result[0], data=data, timeout=3,headers=headers)
  370. print("res_1:",res_1.text)
  371. # 判断文件大小的方法
  372. # path = 'F:\YFWLW\yfwlw\\16_19_21.jpg'
  373. # size = os.path.getsize(path)/1024
  374. print("------------------对接设备图片发送成功!!!")
  375. except Exception as aexc:
  376. print(aexc)
  377. print("------------------对接设备图片发送失败!!!")
  378. except Exception as exce:
  379. print(exce)
  380. print("!!!")
  381. equip = Equip.objects.get(equip_id=imei)
  382. if equip.scene == "1":
  383. mycopyfile("../pyftp/" + os.path.join(a_path, a_name),"../pyftp/scene1/" + os.path.join(a_path, a_name))
  384. # img_addr = "pyftp/scene1/" + os.path.join(event.path, event.name)
  385. elif equip.scene == "2":
  386. mycopyfile("../pyftp/" + os.path.join(a_path, a_name),"../pyftp/scene2/" + os.path.join(a_path, a_name))
  387. # img_addr = "pyftp/scene1/" + os.path.join(event.path, event.name)
  388. elif equip.scene == "3":
  389. mycopyfile("../pyftp/" + os.path.join(a_path, a_name),"../pyftp/scene3/" + os.path.join(a_path, a_name))
  390. # img_addr = "pyftp/scene1/" + os.path.join(event.path, event.name)
  391. elif equip.scene == "4":
  392. mycopyfile("../pyftp/" + os.path.join(a_path, a_name),"../pyftp/scene4/" + os.path.join(a_path, a_name))
  393. # img_addr = "pyftp/scene1/" + os.path.join(event.path, event.name)
  394. sys.stdout = origin
  395. f.close()
  396. return
  397. @shared_task
  398. def test(imei):
  399. # time.sleep(20)
  400. nowtime = datetime.datetime.now().strftime('%Y%m%d')
  401. origin = sys.stdout
  402. f = open('logs/'+"bzyphoto" + nowtime +'.txt','a')
  403. sys.stdout = f
  404. print('=================================================')
  405. print("<-----imei:\n" + imei + ';\n')
  406. print("Message:\n" + "http:bzyphoto" + "----->\n")
  407. print("%s"%datetime.datetime.now())
  408. print('=================================================')
  409. pic_name = datetime.datetime.now().strftime('%Y%m')
  410. try:
  411. args = "pyftp/ftp_file/bzy_test/" + imei
  412. cv_num_list = []
  413. file_list1 = list(paths.list_images(args))
  414. print("\n===========================")
  415. print("file_list1:",file_list1)
  416. print("type file_list1:",type(file_list1))
  417. cv_num_list1 = []
  418. for imagePath1 in file_list1[::]:
  419. # fm = get_value(imagePath)
  420. # 孢子仪图片过小删除
  421. if os.path.getsize(imagePath1) <= 10:
  422. file_list1.remove(imagePath1)
  423. img1 = cv2.imread(imagePath1)
  424. img1 = cv2.resize(img1, (800, 600))
  425. gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
  426. # 创建SIFT对象
  427. sift = cv2.xfeatures2d.SIFT_create()
  428. keypoints, descriptor = sift.detectAndCompute(gray, None)
  429. img1 = cv2.drawKeypoints(image=img1, outImage=img1, keypoints=keypoints,flags=cv2.DRAW_MATCHES_FLAGS_DEFAULT, color=(0, 0, 255))
  430. fm1 = len(keypoints)
  431. cv_num_list1.append(fm1)
  432. # 打印清晰度值:
  433. # print("fm1",fm1)
  434. # # 打印文件路径
  435. # print("imagePath1",imagePath1)
  436. file_cv_tuple1 = tuple(zip(cv_num_list1,file_list1))
  437. print("file_cv_tuple1:\n",file_cv_tuple1)
  438. print("=========================================/n")
  439. file_cv_tuple_list1 = list(file_cv_tuple1)
  440. print("file_cv_tuple_list1:\n",file_cv_tuple_list1)
  441. print("*****************************************/n")
  442. # 按照清晰度排序:, reverse=True降序
  443. result1 = sorted(file_cv_tuple_list1, key=lambda s: s[0],reverse=True)
  444. print("result1:\n",result1)
  445. # 切片取清晰度最高的前五张图片:
  446. result1_5 = result1[0:3]
  447. # result5 = result[0:1]
  448. print("result1_5:\n",result1_5)
  449. pic_name = datetime.datetime.now().strftime('%Y%m')
  450. # 定义要创建的目录:
  451. mkpath="./pyftp/ftp_file/bzy_photo/" + imei + "/" + pic_name
  452. # 调用函数,创建目录:
  453. mkdir(mkpath)
  454. for i in result1_5:
  455. # for i in result5:
  456. #i值:(137.06453470539032, 'images\\192.168.2.64_01_20190802095315882_ALARM_INPUT.jpg')
  457. print("file path:",i[1])
  458. #复制文件:
  459. shutil.copy(i[1],mkpath)
  460. # os.system("rm ./pyftp/ftp_file/bzy_test/%s/*.jpg -rf"%imei)
  461. os.system("mv ./pyftp/ftp_file/bzy_test/%s ./pyftp/ftp_file/bzy_test/%s_%s"%(imei,imei,datetime.datetime.now().strftime("%Y%m%d%H%M%S")))
  462. print("-----------------image move success----------------------")
  463. equip = Equip.objects.get(equip_id=imei)
  464. file_dir="pyftp/ftp_file/bzy_photo/" + imei + "/" + pic_name
  465. for root, dirs, files in os.walk(file_dir):
  466. print("当前目录为=========>>",root) #当前目录路径
  467. print("当前子目录为=========>>",dirs) #当前路径下所有子目录
  468. print("当前目录文件为=========>>",files) #当前路径下所有非目录子文件
  469. for i in files:
  470. photo_addr = file_dir + "/" + i
  471. print("文件夹图片路径===========》》",photo_addr)
  472. if BZYphoto.objects.filter(addr=photo_addr).exists():
  473. print("照片存在")
  474. else:
  475. bzys = BZYphoto.objects.create(equip_id=equip, addr=photo_addr)
  476. print("照片不存在")
  477. if equip.ftp_addr:
  478. bzy_imgs = "http://www.yfzhwlw.com/bzy/" + bzys.addr
  479. data = {
  480. "Image":bzy_imgs,
  481. "imei":bzys.equip_id.equip_id,
  482. }
  483. data = json.dumps(data)
  484. headers = {"Content-Type": "application/json; charset=UTF-8", 'Connection': 'close'}
  485. bzy_photo = requests.post(equip.ftp_addr,data=data,headers=headers,timeout=3)
  486. print("转发成功")
  487. except Exception as a:
  488. print('=================================================')
  489. print("<-----imei:\n" + imei + ';\n')
  490. print("Message:\n" + "http:bzyphoto" + "----->\n")
  491. print("%s"%datetime.datetime.now())
  492. print("==========%s========"%a)
  493. print("-----------------image move default----------------------")
  494. sys.stdout = origin
  495. f.close()
  496. return