← 返回题库
中级

实现设备API Key宽限期轮换

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd, hashlib, secrets
    keys_csv = open_url(____).read()
    keys = pd.read_csv(StringIO(____)).copy()
    GRACE_PERIOD = ____
    def rotate_key(____):
        row = keys_df[keys_df['____']==device_id]
        if row.empty: return None, '____'
        new_raw = '____' + device_id.lower() + '____' + secrets.token_hex(____)
        new_hash = hashlib.sha256(new_raw.encode()).hexdigest()
        return {'____':device_id,'____':new_raw,'____':new_hash[:____]+'____','____':now+GRACE_PERIOD}, '____'
    for did in ['____','____','____']:
        result, msg = rotate_key(____)
        if msg == '____':
            print("____" + did + "____" + result['____'] + "____" + str(____))

示例

输入
solve()
期望输出
Rotated RPI-001: new_hash=80185f29488dfc9d... grace_until=1748739600
Rotated ESP-001: new_hash=eec60a2aec80383a... grace_until=1748739600
Rotated ARD-001: new_hash=ae85965e3b24ed0d... grace_until=1748739600
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码