m1/myrequests.py
2020-04-17 11:37:13 +08:00

25 lines
783 B
Python

# -*- coding: utf-8 -*-
import requests
import json
def myrequests(url, data, methods="get"):
requests.adapters.DEFAULT_RETRIES = 5 # 增加重连次数
s = requests.session()
s.keep_alive = False # 关闭多余连接
if methods == "get":
return s.get(url=url, data=data)
elif methods == "post":
if isinstance(data, "str"):
headers = {'Content-Type': 'application/json'}
return s.get(url=url, headers=headers, data=json.dumps(data))
elif isinstance(data, ("tuple", "dict", "list")):
return s.get(url=url, json=data)
else:
print(f"pls input data not {type(data)}\t{data}")
return False
else:
print(f"pls input methods not {methods}")
return False