Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip language option tags without value at AtCoder #739

Merged
merged 1 commit into from
May 1, 2020

Conversation

serihiro
Copy link
Contributor

@serihiro serihiro commented May 1, 2020

What does this PR change?

This PR fixes a parse error when parsing available languages from AtCoder submit pages.

Background

When I tried to submit my code to AtCoder, I faced the following error today.

$ oj -v s https://atcoder.jp/contests/abc055/tasks/abc055_b main.cpp

...

Traceback (most recent call last):
  File "/Users/kazuhiroserizawa/.pyenv/versions/3.8.0/lib/python3.8/site-packages/onlinejudge/_implementation/main.py", line 233, in main
    run_program(namespace, parser=parser)
  File "/Users/kazuhiroserizawa/.pyenv/versions/3.8.0/lib/python3.8/site-packages/onlinejudge/_implementation/main.py", line 212, in run_program
    submit(args)
  File "/Users/kazuhiroserizawa/.pyenv/versions/3.8.0/lib/python3.8/site-packages/onlinejudge/_implementation/command/submit.py", line 56, in submit
    language_dict = {language.id: language.name for language in problem.get_available_languages(session=sess)}  # type: Dict[LanguageId, str]
  File "/Users/kazuhiroserizawa/.pyenv/versions/3.8.0/lib/python3.8/site-packages/onlinejudge/service/atcoder.py", line 869, in get_available_languages
    data = self.download_data(session=session)
  File "/Users/kazuhiroserizawa/.pyenv/versions/3.8.0/lib/python3.8/site-packages/onlinejudge/service/atcoder.py", line 804, in download_data
    return AtCoderProblemDetailedData.from_html(html, problem=self, session=session, response=resp, timestamp=timestamp)
  File "/Users/kazuhiroserizawa/.pyenv/versions/3.8.0/lib/python3.8/site-packages/onlinejudge/service/atcoder.py", line 760, in from_html
    available_languages = cls._parse_available_languages(soup, problem=problem)
  File "/Users/kazuhiroserizawa/.pyenv/versions/3.8.0/lib/python3.8/site-packages/onlinejudge/service/atcoder.py", line 728, in _parse_available_languages
    languages += [Language(option.attrs['value'], option.string)]
KeyError: 'value'

[ERROR] 'value'

This error was caused by the modification of the Form of ActCoder's submit pages.
The language select list has an empty option tag for search now.

Because current implementation of oj does not expect option tags without value element, key error occurs when parsing the empty option tag.

cap

This PR modifies the implementation to skip empty option tags.

@serihiro
Copy link
Contributor Author

serihiro commented May 1, 2020

Two test cases failed at CI 🤔
But I think these failures are not related to this PR.

-- Docs: https://docs.pytest.org/en/latest/warnings.html
=========================== short test summary info ===========================
FAILED tests/service_codeforces.py::CodeforcesProblemTest::test_download_problem
FAILED tests/service_yukicoder.py::YukicoderOfficialAPITest::test_get_user_0
= 2 failed, 228 passed, 36 skipped, 2 xfailed, 10 warnings in 195.97s (0:03:15) =
Command exited with code 1

Copy link
Member

@kmyk kmyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
I could reproduce the error and confirmed that this pullreq fixes it.

Thank you for a nice pull request!

@kmyk
Copy link
Member

kmyk commented May 1, 2020

CI fails, but not related for this problem. I'll fix it and merge this soon.

@kmyk kmyk merged commit e533390 into online-judge-tools:master May 1, 2020
@serihiro serihiro deleted the fix-key-error branch May 1, 2020 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants