import requests,json

def getData(url,headers=None,body=None,params=None,methods='get',timeout=None,decoder='utf8',ty=None):
    if methods=='get':
        if ty =='img':
            request = requests.get(url=url, headers=headers, json=body, params=params, timeout=timeout)
            return request.content
        else:
            request = requests.get(url=url, headers=headers, json=body, params=params,timeout=timeout)
    elif methods=='post':
        request = requests.post(url=url,headers=headers,json=body,params=params,timeout=timeout)
    else:
        request='请求失败'
    result = request.text.encode(decoder)
    if isinstance(result, bytes):
        result = str(result, encoding='utf-8')
    if isinstance(result, str):
        try:
            while isinstance(result, str):
                result = json.loads(result)
        except:
            result = {"code":"404"}
    if 'code' not in result:
        result['code'] ='0'
    return result