You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Webuntis API?登录报错bad credentials问题求助

WebUntis API 登录错误(code -8504: bad credentials)排查方案

问题概述

目标是通过WebUntis API获取考试日期并同步到Google Calendar,但登录时始终返回错误:

Error: Failed to login. {"jsonrpc":"2.0","id":"Awesome","error":{"message":"bad credentials","code":-8504}}

已尝试JavaScript和Python两种语言的实现,均出现相同错误;已排查过更换服务器URL/学校名称、重装webuntis库、测试其他函数参数,且确认用户名密码正确(仅示例中做了修改)。

测试代码

JavaScript 实现

const { WebUntis } = require('webuntis');

async function main() {
  const untis = new WebUntis('BK-Beckum', 'name', 'Password', 'tritone.webuntis.com');
  await untis.login();

  const timetable = await untis.getStudents();
  console.log(timetable);

  await untis.logout()
}

main();

Python 实现

import webuntis

s = webuntis.Session(
    username="EngelhCar",
    password="Password",
    server = "tritone.webuntis.com",
    school = "BK-Beckum",
    useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0"
)

s.login()
for klass in s.klassen():
    print(klass.name)
s.logout()

排查步骤

  1. 确认学校代码的准确性
    WebUntis的school参数不是显示名称,可能是学校内部标识符。打开WebUntis网页登录页,搜索学校后查看URL中的school参数(比如https://tritone.webuntis.com/WebUntis/?school=BK-Beckum#/basic/login),直接复制该参数值,避免手动输入时的拼写、连字符等错误。

  2. 验证服务器地址
    确保服务器地址是学校实际使用的域名:登录WebUntis网页版,复制地址栏的主域名(比如tritone.webuntis.com),不要添加https://或后续路径。

  3. 检查账户权限
    部分WebUntis账户(尤其是学生账户)可能没有API访问权限:

    • 用相同账户登录WebUntis网页版,确认能正常查看考试信息;
    • 联系学校管理员,确认该账户是否允许API调用。
  4. 处理密码特殊字符
    如果密码包含!@#$%^&*或反斜杠等特殊字符:

    • JavaScript中确保字符串引号不冲突;
    • Python中使用原始字符串(r"你的密码")避免转义问题。
  5. 库版本兼容性测试
    不同版本的webuntis库可能存在API差异:

    • JavaScript:执行npm list webuntis查看版本,尝试安装稳定版(比如npm install webuntis@2.0.0);
    • Python:执行pip show webuntis查看版本,尝试降级或升级(比如pip install webuntis==0.1.12)。
  6. 手动API请求测试
    用curl直接发送登录请求,排除库的问题:

    curl -X POST https://tritone.webuntis.com/WebUntis/jsonrpc.do \
    -H "Content-Type: application/json" \
    -d '{
        "jsonrpc": "2.0",
        "method": "authenticate",
        "params": {
            "user": "你的用户名",
            "password": "你的密码",
            "school": "BK-Beckum",
            "client": "Awesome"
        },
        "id": "Awesome"
    }'
    

    如果返回相同错误,说明问题出在账户/学校信息;如果成功,再排查代码中库的调用逻辑。

内容的提问来源于stack exchange,提问作者Carsten

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 18:33:10