-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
40 lines (34 loc) · 967 Bytes
/
helper.py
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
#!/usr/bin/env python
# -*-coding:utf-8-*-
import json
import sys
import os
def toDict(val):
# convert any 'AttributeDict' type found to 'dict'
parsedDict = dict(val)
for key, val in parsedDict.items():
if 'list' in str(type(val)):
parsedDict[key] = [_parseValue(x) for x in val]
else:
parsedDict[key] = _parseValue(val)
return parsedDict
def _parseValue(val):
# check for nested dict structures to iterate through
if 'dict' in str(type(val)).lower():
return toDict(val)
# convert 'HexBytes' type to 'str'
elif 'HexBytes' in str(type(val)):
return val.hex()
else:
return val
def to_many_request(e):
if "Draining connection" in str(e):
return True
elif "Too many requests" in str(e):
return True
elif "HTTP 429" in str(e):
return True
elif "execution aborted" in str(e):
return True
else:
return False