zhongxinghong / PKUAutoElective

北大选课网补退选阶段自动选课小工具
MIT License
668 stars 231 forks source link

选课时遇到错误 #6

Closed bob-lytton closed 5 years ago

bob-lytton commented 5 years ago

Check List

Version / Environment

System infomation: [Ubuntu 16.04 ] ( Windows10 64bit, MacOS 10.13.6, Ubuntu 18.04.3 amd64, ... ) Python version: [python 3.5.2 ] ( run python3 --version ) AutoElective version: [2.0.4 ] ( run python3 main.py --version )

Config

# filename: config.ini
# coding: utf-8

[coding]

# csv_coding   str   course.csv 的编码,可选 ("utf-8","gbk")

csv_coding = utf-8

[user]

# student_ID    string    学号
# password      string    密码
# dual_degree   boolean   是否为双学位账号,可选 (true, false, True, False, 1, 0)
# identity      string    双学位账号登录身份,可选 ("bzx","bfx") 对应于 “主修/辅双”

student_ID = xxxxxxxxxxxxxxxx
password = xxxxxxxxxxxxxxxx
dual_degree = false
identity = bzx

[client]

# supply_cancel_page           int       待刷课程处在选课计划的第几页
# refresh_interval             float     每次循环后的暂停时间,单位 s
# random_deviation             float     偏移量分数,如果设置为 <= 0 的值,则视为 0
# iaaa_client_timeout          float     IAAA 客户端最长请求超时
# elective_client_timeout      float     elective 客户端最长请求超时
# elective_client_pool_size    int       最多同时保持几个 elective 的有效会话
# login_loop_interval          float     IAAA 登录线程每回合结束后的等待时间
# debug_print_request          boolean   是否打印请求细节
# debug_dump_request           boolean   是否将重要接口的请求以日志的形式记录到本地(包括补退选页、提交选课等接口)
#
# 关于刷新间隔的配置示例:
#
# refresh_interval = 8
# random_deviation = 0.2
#
# 则每两个循环的间隔时间为 8 * (1.0 ± 0.2) s

supply_cancel_page = 1
refresh_interval = 5
random_deviation = 0.2
iaaa_client_timeout = 30
elective_client_timeout = 60
elective_client_pool_size = 4
login_loop_interval = 2
debug_print_request = false
debug_dump_request = false

[monitor]

host = 127.0.0.1
port = 7074

Issue Description

What

我遇到这样的问题, 在要刷的课有名额的时候,验证码识别错误 终端输出如下

Console Log

[INFO] loop, 15:29:36, 
[INFO] loop, 15:29:36, Get SupplyCancel page 1
[INFO] loop, 15:29:36, Get available courses
[INFO] loop, 15:29:36, Course(操作系统A, 1, 信息科学技术学院, 180 / 0) is AVAILABLE now !
[INFO] loop, 15:29:36, Course(数理逻辑, 1, 信息科学技术学院, 260 / 0) is AVAILABLE now !
[INFO] loop, 15:29:36, Try to elect Course(操作系统A, 1, 信息科学技术学院, 180 / 0)
[INFO] loop, 15:29:36, Fetch a captcha
[INFO] loop, 15:29:36, Recognition result: jjjj
[INFO] loop, 15:29:36, Validation failed, try again
[INFO] loop, 15:29:36, Fetch a captcha
[INFO] loop, 15:29:36, Recognition result: jjjj
[INFO] loop, 15:29:36, Validation failed, try again
[INFO] loop, 15:29:36, Fetch a captcha
[INFO] loop, 15:29:36, Recognition result: jjjj
[INFO] loop, 15:29:36, Validation failed, try again
[INFO] loop, 15:29:36, Fetch a captcha
...
[ERROR] loop.error, 15:29:37, Expecting value: line 5 column 1 (char 8)
[ERROR] loop.error, 15:29:37, OperationFailedError does not take keyword arguments
Traceback (most recent call last):
  File "/media/bob-lytton/MyData/repos/PKUAutoElective/autoelective/loop.py", line 151, in _task_validate_captcha
    res = r.json()["valid"]  # 可能会返回一个错误网页 ...
  File "/usr/lib/python3/dist-packages/requests/models.py", line 808, in json
    return complexjson.loads(self.text, **kwargs)
  File "/home/bob-lytton/.local/lib/python3.5/site-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/home/bob-lytton/.local/lib/python3.5/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/home/bob-lytton/.local/lib/python3.5/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 5 column 1 (char 8)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/media/bob-lytton/MyData/repos/PKUAutoElective/autoelective/loop.py", line 374, in _thread_main_loop
    _task_validate_captcha(elective)
  File "/media/bob-lytton/MyData/repos/PKUAutoElective/autoelective/loop.py", line 154, in _task_validate_captcha
    raise OperationFailedError(msg="Unable to validate captcha")
TypeError: OperationFailedError does not take keyword arguments

Reproduce

如有必要,提供复现的步骤

bob-lytton commented 5 years ago

发现好像是自己运行的时候没有打开对应的虚拟环境,结合之前打开虚拟环境后运行成功,所以认为这个问题暂时已被解决

zhongxinghong commented 5 years ago

@bob-lytton 其实你提醒了我一个错误 orz ... OperationFailedError 这个类确实是写错了一个地方 ...

关于你遇到的验证码不能识别的问题,我个人觉得是因为选课网的问题

[INFO] loop, 15:29:36, Course(操作系统A, 1, 信息科学技术学院, 180 / 0) is AVAILABLE now !
[INFO] loop, 15:29:36, Course(数理逻辑, 1, 信息科学技术学院, 260 / 0) is AVAILABLE now !

我前段时间很偶然地遇到过这种课程已选人数突然降为 0 的问题,它非常罕见。应该下一个回合发回来的包就是对的。

simplejson.errors.JSONDecodeError: Expecting value: line 5 column 1 (char 8)

这个错误是因为对方发回来的 response body 不是 JSON 格式,很有可能是发了一个网页回来,应该会带有一个错误提示(我曾经遇到过未同意选课协议的提示)。

我觉得这可能就是一个选课网的偶发错误,可能它正在更新数据或者重启应用啥的 ... 但是因为没有 dump request ,当时的情况也复现不了了,我也就只能猜测到这个程度了 ...