Commit 0b7fa0fc by lichenggang

digkey token失败后报警

parent 9a0d68d4
......@@ -4,8 +4,9 @@ import traceback
import redis
import requests
from retry import retry
import token_lib
from utils.robots import dd_send_msg
PLATFORM = "apidigikey"
LEVEL = "HH"
......@@ -47,6 +48,7 @@ class DGTokenCrawler(token_lib.BaseTokenCrawler):
access_token, refresh_token = self.get_token_by_refresh_token()
return access_token, refresh_token
except Exception:
dd_send_msg('digikey token同步失败:' + traceback.format_exc())
self.logger.error(traceback.format_exc())
def get_token(self):
......@@ -65,6 +67,7 @@ class DGTokenCrawler(token_lib.BaseTokenCrawler):
token_json = resp.json()
return token_json['access_token'], token_json['refresh_token']
@retry(tries=3)
def get_token_by_refresh_token(self):
refresh_token = self._redis.get(self.refresh_token_key).decode()
p_data = {
......@@ -74,13 +77,11 @@ class DGTokenCrawler(token_lib.BaseTokenCrawler):
# 'refresh_token': 'jwki255qAu14VPDGhuJKQVPHixiAGO1D',
'grant_type': 'refresh_token'
}
resp = requests.post(p_url, headers=p_headers, data=p_data)
resp = requests.post(p_url, headers=p_headers, data=p_data, timeout=(15, 20))
token_json = resp.json()
return token_json['access_token'], token_json['refresh_token']
def process(self, is_main):
access_token, refresh_token = self.collect_token()
print(access_token)
print(refresh_token)
self._redis.set(self.token_key, access_token)
self._redis.set(self.refresh_token_key, refresh_token)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
\ No newline at end of file
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import time
import requests
dd_robot_api = ' https://oapi.dingtalk.com/robot/send?access_token='
tom = 'c19beeab837f5c6e019e7fc602d470704d634ae33510f40fb0e903cde215fb24'
def dd_send_msg(msg, robot=tom):
data = {
"msgtype": "text",
"text": {
"content": msg
}
}
requests.post(dd_robot_api + robot, json=data)
time.sleep(5)
if __name__ == "__main__":
dd_send_msg('喂喂 你发的太多了!')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment