retry_model.py
1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# @auther : Ylei
# @date : 2019/11/18
# @File : retry_model.py
# @Software : PyCharm
from retry import retry
import requests
import json
from log_module import logger
log_retry_send = logger('data_info_retry_send.log')
#from app import log_vehicle
#from app import log_illegal
#from app import log_event
#from app import log_flow
@retry(delay=1,backoff=2,max_delay=8)
def retry_send(arguments):
print('in ........retry_send','---------------######',arguments[2])
headers = {'Content-Type': 'application/json'}
try:
r = requests.post(url=arguments[0],headers=headers, data=arguments[1])
except Exception as e:
#print('error :%s' %e)
arguments[2].debug('unreachable--- send data in url is :%s' %(arguments[0]))
#print(r.content,type(r.content),json.loads(r.content)['code'],type(json.loads(r.content)['code']),'***********in retry_send')
if json.loads(r.content)['Code'] == 0:
#if r.status_code == 200:
try:
arguments[2].debug('send code is :%s url is :%s' %(json.loads(r.content)['Code'],arguments[0]))
except Exception as e:
print('retry_send-----execpt---99999',e)
print('in retry_send ---success')
else:
print('return code is :%s retry data in url is :%s' %(json.loads(r.content)['Code'],arguments[0]))
arguments[2].debug('return code is :%s send data in url is :%s' %(json.loads(r.content)['Code'],arguments[0]))
raise 'SendFaild'
#return json.loads(r.content)['code']
return json.loads(r.content)
if __name__ == '__main__':
url = 'http://192.168.9.167:21182/api/v1/recv/events'
data = 1111
retry_send([url, json.dumps(data),log_retry_send])