import requests

def get_all_sample_info(sample_accession):
    """获取样本的所有可用信息"""
    url = 'https://www.ebi.ac.uk/ena/portal/api/filereport'
    params = {
        "accession": sample_accession,
        "result": "read_run",
        "format": "json",
        "fields": "all"  # 请求所有字段
    }
    
    try:
        response = requests.get(url, params=params, timeout=30)
        if response.status_code == 200:
            data = response.json()
            if data:
                sample_info = data[0]
                print(f"样本 {sample_accession} 的所有可用字段:")
                for key, value in sample_info.items():
                    print(f"- {key}: {value}")
                return sample_info
            else:
                print("警告: 返回空数据")
                return {}
        else:
            print(f"错误: 服务器返回状态码 {response.status_code}")
            return {}
    except Exception as e:
        print(f"错误: 发生异常: {str(e)}")
        return {}

# 调用函数获取样本的所有信息
get_all_sample_info("ERR4586324")  # 使用一个示例样本ID