拼接网址函数
url = 'http://localhost.com'
def makeurl(*res):
lst_res = list(res)
for i in range(0,len(lst_res)):
res = lst_res[i]
if res.endswith('/') or res.startswith('/'):
lst_res[i] == res.strip('/')
lst_res.insert(0,url)
return '/'.join(lst_res)
url = makeurl('ceshi','logins')
请求网址连接重试装饰器
def retry(exception=Timeout,max_times=3):
def inner(func):
def warp(*args,**kwargs):
for try_time in range(max_times):
try:
return func(*args,**kwargs)
except exception as e:
if try_time == max_times -1:
raise e
time.sleep(3)
print('重试上一次请求')
continue
return warp
return inner