online-judge-tools / api-client

API client to develop tools for competitive programming
MIT License
67 stars 22 forks source link

Receiving `You may use wrong User-Agent` when submitting to Codeforces #117

Closed hotarunw closed 3 years ago

hotarunw commented 4 years ago

Description

When I try to submit to Codeforces, it receives wrong User-Agent error message and this submission failed.

[WARNING] You may use wrong User-Agent: 'online-judge-tools/11.1.1 (+https://github.com/online-judge-tools/oj)'
[FAILURE] submission failed

Error log

I have already signed into Codeforces using CUI-based login. ```console $ oj login https://codeforces.com/contest/1447/problem/A [INFO] online-judge-tools 11.1.1 (+ online-judge-api-client 10.5.0) [INFO] service recognized: CodeforcesService.from_url('https://codeforces.com/'): https://codeforces.com/contest/1447/problem/A [NETWORK] GET: https://codeforces.com/enter [NETWORK] 200 OK [FAILURE] You are not signed in. [INFO] Trying to open Chrome via WebDriver... [ERROR] Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home [INFO] Trying to open Firefox via WebDriver... [ERROR] Message: 'geckodriver' executable needs to be in PATH. [INFO] Trying to open Edge via WebDriver... [ERROR] Message: 'MicrosoftWebDriver.exe' executable needs to be in PATH. Please download from http://go.microsoft.com/fwlink/?LinkId=619687 [INFO] Trying to open Internet Explorer via WebDriver... [ERROR] Message: 'IEDriverServer.exe' executable needs to be in PATH. Please download from http://selenium-release.storage.googleapis.com/index.html and read up at https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver [INFO] Trying to open Safari via WebDriver... [ERROR] SafariDriver was not found; are you running Safari 10 or later? You can download Safari at https://developer.apple.com/safari/download/. [INFO] Trying to open Opera via WebDriver... [ERROR] Message: 'operadriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home [ERROR] No WebDriver is available. [HINT] Please install a WebDriver. See https://www.selenium.dev/documentation/en/webdriver/driver_requirements/ Detailed instructions: If you use Ubuntu: 1. Run $ sudo apt install chromium-chromedriver firefox-geckodriver If you use Ubuntu under Windows Subsystem for Linux: 1. Make a symbolic link from cookie.jar in WSL to cookie.jar out of WSL. For example, run $ ln -s /mnt/c/Users/%USERNAME%/AppData/Local/online-judge-tools/online-judge-tools/cookie.jar /home/ubuntu/.local/share/online-judge-tools/cookie.jar 2. Use `oj login` outside of WSL If you use Windows: 1. Install Chocolatey. See https://chocolatey.org/ 2. Run > choco install selenium-all-drivers [WARNING] Switch to use CUI-based login instead of Selenium [NETWORK] GET: https://codeforces.com/enter [NETWORK] 200 OK Username: seiran Password: [NETWORK] POST: https://codeforces.com/enter [NETWORK] redirected to: https://codeforces.com/ [NETWORK] 200 OK [INFO] Welcome, seiran. [NETWORK] GET: https://codeforces.com/enter [NETWORK] 302 Found [SUCCESS] You have already signed in. [INFO] save cookie to: /home/hotaru/.local/share/online-judge-tools/cookie.jar ```
$ oj s submit.cpp
[INFO] online-judge-tools 11.1.1 (+ online-judge-api-client 10.5.0)
[INFO] read history from: /home/hotaru/.cache/online-judge-tools/download-history.jsonl
[INFO] found urls in history:
https://codeforces.com/contest/1447/problem/A
[INFO] guessed problem: https://codeforces.com/contest/1447/problem/A
[INFO] problem recognized: CodeforcesProblem.from_url('https://codeforces.com/contest/1447/problem/A'): https://codeforces.com/contest/1447/problem/A
[INFO] code (1239 byte):

** MY SOLUTION **

[INFO] load cookie from: /home/hotaru/.local/share/online-judge-tools/cookie.jar
[NETWORK] GET: https://codeforces.com/enter
[NETWORK] 302 Found
[INFO] You are logged in.
[NETWORK] GET: https://codeforces.com/contest/1447/problem/A
[NETWORK] 200 OK
[INFO] both GCC and Clang are available for C++ compiler
[INFO] use: GCC
[INFO] chosen language: 61 (GNU G++17 9.2.0 (64 bit, msys 2))
[INFO] sleep(3.00)
Are you sure? [y/N] y
[NETWORK] GET: https://codeforces.com/contest/1447/problem/A
[NETWORK] 200 OK
[NETWORK] POST: https://codeforces.com/contest/1447/problem/A
[NETWORK] 403 Forbidden
[ERROR] 403 Client Error:  for url: https://codeforces.com/contest/1447/problem/A
Traceback (most recent call last):
  File "/home/hotaru/.local/lib/python3.8/site-packages/onlinejudge/service/codeforces.py", line 389, in submit_code
    resp.raise_for_status()
  File "/home/hotaru/.local/lib/python3.8/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error:  for url: https://codeforces.com/contest/1447/problem/A
[WARNING] You may use wrong User-Agent: 'online-judge-tools/11.1.1 (+https://github.com/online-judge-tools/oj)'
[FAILURE] submission failed

Environment

Ubuntu under Windows Subsystem for Linux

Windows

WSL

Python and oj

$ python3 --version
Python 3.8.5
$ oj --version
online-judge-tools 11.1.1 (+ online-judge-api-client 10.5.0)

Other notes

kmyk commented 4 years ago

@hotaroon Thank you for reporting! (This is well-written bugreport :smile:)

Conclusion: Let me wait and see how it goes.

While waiting, the same issue will reported at cf-tool, or Codeforces may change the logic. I'll investigate further when this is not fixed even after a while (in this weekend?)

Observation

I could reproduce the issue, but the precise condition is still unknown. My observations are:

  1. At first, the submissions succeeded regardless the User-Agent. (User-Agent is irreverent)
  2. The first few times submissions succeeded, but after all submissions failed. (it seems "banned")
  3. Submissions from my GUI browser (Google Chrome) succeeds even after the "ban". (the "ban" is not associated with IP address nor account)
  4. However, after removing the cookie ~/.local/share/online-judge-tools/cookie.jar and re-login, submissions from online-judge-tools still fails. (the "ban" is not associated with the session)

There are many difference between HTTP requests from online-judge-tools and from GUI browsers (e.g. referer, CSRF token, etc.), so probably one of them is the cause.

Logs

User-Agent requests/2.24.0, success

``` console $ oj-api submit-code https://codeforces.com/contest/1336/problem/A --file foo.cpp --language 61 INFO:onlinejudge_api.main:online-judge-api-client 10.5.0 INFO:onlinejudge_api.main:sleep 1.000000 sec INFO:onlinejudge.dispatch:problem recognized: CodeforcesProblem.from_url('https://codeforces.com/contest/1336/problem/A'): https://codeforces.com/contest/1336/problem/A INFO:onlinejudge.dispatch:contest recognized: : https://codeforces.com/contest/1336/problem/A INFO:onlinejudge.dispatch:service recognized: CodeforcesService.from_url('https://codeforces.com/'): https://codeforces.com/contest/1336/problem/A INFO:onlinejudge.utils:load cookie from: /home/user/.local/share/online-judge-tools/cookie.jar INFO:onlinejudge._implementation.utils:network: GET: https://codeforces.com/contest/1336/problem/A INFO:onlinejudge._implementation.utils:network: 200 OK INFO:onlinejudge._implementation.utils:network: POST: https://codeforces.com/contest/1336/problem/A INFO:onlinejudge._implementation.utils:network: redirected to: https://codeforces.com/contest/1336/my INFO:onlinejudge._implementation.utils:network: 200 OK INFO:onlinejudge.service.codeforces:success: result: https://codeforces.com/contest/1336/my INFO:onlinejudge.utils:save cookie to: /home/user/.local/share/online-judge-tools/cookie.jar {"status": "ok", "messages": [], "result": {"url": "https://codeforces.com/contest/1336/my"}} ```

User-Agent online-judge-tools/11.1.1 (+https://github.com/online-judge-tools/oj), success

``` console $ oj s https://codeforces.com/contest/1447/problem/A foo.cpp [INFO] online-judge-tools 11.1.1 (+ online-judge-api-client 10.5.0) [INFO] read history from: /home/user/.cache/online-judge-tools/download-history.jsonl [INFO] found urls in history: [INFO] problem recognized: CodeforcesProblem.from_url('https://codeforces.com/contest/1447/problem/A'): https://codeforces.com/contest/1447/problem/A [INFO] code (12 byte): hello world [INFO] load cookie from: /home/user/.local/share/online-judge-tools/cookie.jar [NETWORK] GET: https://codeforces.com/enter [NETWORK] 302 Found [INFO] You are logged in. [NETWORK] GET: https://codeforces.com/contest/1447/problem/A [NETWORK] 200 OK [INFO] both GCC and Clang are available for C++ compiler [INFO] use: GCC [INFO] chosen language: 61 (GNU G++17 9.2.0 (64 bit, msys 2)) [WARNING] the problem "https://codeforces.com/contest/1447/problem/A" is specified to submit, but no samples were downloaded in this directory. this may be mis-operation [INFO] sleep(3.00) Are you sure? Please type "A" A [NETWORK] GET: https://codeforces.com/contest/1447/problem/A [NETWORK] 200 OK [NETWORK] POST: https://codeforces.com/contest/1447/problem/A [NETWORK] redirected to: https://codeforces.com/contest/1447/my [NETWORK] 200 OK [SUCCESS] result: https://codeforces.com/contest/1447/my [INFO] open the submission page with browser: [INFO] save cookie to: /home/user/.local/share/online-judge-tools/cookie.jar ```

User-Agent online-judge-tools/11.1.1 (+https://github.com/online-judge-tools/oj), failure

```console $ oj s https://codeforces.com/contest/1447/problem/A foo.cpp [INFO] online-judge-tools 11.1.1 (+ online-judge-api-client 10.5.0) [INFO] read history from: /home/user/.cache/online-judge-tools/download-history.jsonl [INFO] found urls in history: [INFO] problem recognized: CodeforcesProblem.from_url('https://codeforces.com/contest/1447/problem/A'): https://codeforces.com/contest/1447/problem/A [INFO] code (24 byte): hello hello world hello [INFO] load cookie from: /home/user/.local/share/online-judge-tools/cookie.jar [NETWORK] GET: https://codeforces.com/enter [NETWORK] 302 Found [INFO] You are logged in. [NETWORK] GET: https://codeforces.com/contest/1447/problem/A [NETWORK] 200 OK [INFO] both GCC and Clang are available for C++ compiler [INFO] use: GCC [INFO] chosen language: 61 (GNU G++17 9.2.0 (64 bit, msys 2)) [WARNING] the problem "https://codeforces.com/contest/1447/problem/A" is specified to submit, but no samples were downloaded in this directory. this may be mis-operation [INFO] sleep(3.00) Are you sure? Please type "A" A [NETWORK] GET: https://codeforces.com/contest/1447/problem/A [NETWORK] 200 OK [NETWORK] POST: https://codeforces.com/contest/1447/problem/A [NETWORK] 403 Forbidden [ERROR] 403 Client Error: for url: https://codeforces.com/contest/1447/problem/A Traceback (most recent call last): File "/home/user/.local/lib/python3.6/site-packages/onlinejudge/service/codeforces.py", line 389, in submit_code resp.raise_for_status() File "/home/user/.local/lib/python3.6/site-packages/requests/models.py", line 943, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 403 Client Error: for url: https://codeforces.com/contest/1447/problem/A [WARNING] You may use wrong User-Agent: 'online-judge-tools/11.1.1 (+https://github.com/online-judge-tools/oj)' [FAILURE] submission failed ```

User-Agent Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36, failure

$ oj-api --user-agent 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36' submit-code https://codeforces.com/contest/1336/problem/A --file foo.cpp --language 61 INFO:onlinejudge_api.main:online-judge-api-client 10.5.0 INFO:onlinejudge_api.main:sleep 1.000000 sec INFO:onlinejudge.dispatch:problem recognized: CodeforcesProblem.from_url('https://codeforces.com/contest/1336/problem/A'): https://codeforces.com/contest/1336/problem/A INFO:onlinejudge.dispatch:contest recognized: : https://codeforces.com/contest/1336/problem/A INFO:onlinejudge.dispatch:service recognized: CodeforcesService.from_url('https://codeforces.com/'): https://codeforces.com/contest/1336/problem/A INFO:onlinejudge.utils:load cookie from: /home/user/.local/share/online-judge-tools/cookie.jar INFO:onlinejudge._implementation.utils:network: GET: https://codeforces.com/contest/1336/problem/A INFO:onlinejudge._implementation.utils:network: 200 OK INFO:onlinejudge._implementation.utils:network: POST: https://codeforces.com/contest/1336/problem/A INFO:onlinejudge._implementation.utils:network: 403 Forbidden ERROR:onlinejudge.service.codeforces:403 Client Error: for url: https://codeforces.com/contest/1336/problem/A Traceback (most recent call last): File "/home/user/.local/lib/python3.6/site-packages/onlinejudge/service/codeforces.py", line 389, in submit_code resp.raise_for_status() File "/home/user/.local/lib/python3.6/site-packages/requests/models.py", line 943, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 403 Client Error: for url: https://codeforces.com/contest/1336/problem/A WARNING:onlinejudge.service.codeforces:You may use wrong User-Agent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36' ERROR:onlinejudge_api.main:You may use wrong User-Agent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36': 403 Client Error: for url: https://codeforces.com/contest/1336/problem/A Traceback (most recent call last): File "/home/user/.local/lib/python3.6/site-packages/onlinejudge/service/codeforces.py", line 389, in submit_code resp.raise_for_status() File "/home/user/.local/lib/python3.6/site-packages/requests/models.py", line 943, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 403 Client Error: for url: https://codeforces.com/contest/1336/problem/A During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/user/.local/lib/python3.6/site-packages/onlinejudge_api/main.py", line 288, in main result = submit_code.main(problem, file=parsed.file, language_id=parsed.language, session=session) File "/home/user/.local/lib/python3.6/site-packages/onlinejudge_api/submit_code.py", line 31, in main submission = problem.submit_code(code, language_id=language_id, filename=str(file), session=session) File "/home/user/.local/lib/python3.6/site-packages/onlinejudge/service/codeforces.py", line 394, in submit_code raise SubmissionError('You may use wrong User-Agent: {}: {}'.format(repr(session.headers.get('User-Agent')), e)) onlinejudge.type.SubmissionError: You may use wrong User-Agent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36': 403 Client Error: for url: https://codeforces.com/contest/1336/problem/A {"status": "error", "messages": ["onlinejudge.type.SubmissionError: You may use wrong User-Agent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36': 403 Client Error: for url: https://codeforces.com/contest/1336/problem/A"], "result": null}
kmyk commented 4 years ago

I merged a commit https://github.com/online-judge-tools/api-client/pull/120 to fix this issue.

I think this is fixed, but it's difficult to prove that this types of problems are truly fixed. Please re-open or comment to this issue when this issue remains.

peroon commented 4 years ago

同じ問題が私にも今起こりました。ojは最新です。

提出用formタグを見てみるとcsrf_tokenが設定されているようで、 一方ojのcodeforces.pyにはその記述はありません。

これは関係ないでしょうか? (的はずれな指摘でしたらすみません・・・)

R1B3n-13 commented 4 years ago

The issue remains after the update. :sob::sob:

kmyk commented 4 years ago

Okay. I'll investigate this issue again :bow:

kmyk commented 4 years ago

I cannot reproduce this error now. All of consecutive eight submissions succeeded. It seems to be fixed, at least on my environment.

@peroon 分かりにくいんですが csrf_token は実はすでに含まれているはずです。<form> タグが解析され自動で送信されています。(リンク) @peroon @Tard1grad3 Can you give me the detailed log ($ oj --verbose s https://... ... or something) with contexts (e.g. the first and second submission succeeded but the third submission failed.)? For this, please be careful not to include secret values like CSRF tokens. Thank you!

hotarunw commented 4 years ago

@kmyk This is my detailed log. I've submitted 2-3 times, but all submissions have failed. (I hid CSRF token.)

$ oj --verbose s https://codeforces.com/contest/1454/problem/B submit.cpp
[DEBUG] load the cache for update checking: /home/hotaru/.cache/online-judge-tools/pypi.json
[DEBUG] load the cache for update checking: /home/hotaru/.cache/online-judge-tools/pypi.json
[DEBUG] args: Namespace(cookie=PosixPath('/home/hotaru/.local/share/online-judge-tools/cookie.jar'), file=PosixPath('submit.cpp'), guess=True, guess_cxx_compiler='gcc', guess_cxx_latest=True, guess_python_interpreter='cpython', guess_python_version='auto', language=None, open=True, subcommand='s', url='https://codeforces.com/contest/1454/problem/B', verbose=True, version=False, wait=3, yes=True)
[INFO] online-judge-tools 11.1.1 (+ online-judge-api-client 10.6.0)
[INFO] read history from: /home/hotaru/.cache/online-judge-tools/download-history.jsonl
[INFO] found urls in history:
https://codeforces.com/contest/1454/problem/B
[INFO] problem recognized: CodeforcesProblem.from_url('https://codeforces.com/contest/1454/problem/B'): https://codeforces.com/contest/1454/problem/B
[INFO] code (908 byte):

** MY SOLUTION **

[DEBUG] User-Agent: online-judge-tools/11.1.1 (+https://github.com/online-judge-tools/oj)
[INFO] load cookie from: /home/hotaru/.local/share/online-judge-tools/cookie.jar
[NETWORK] GET: https://codeforces.com/enter
[DEBUG] Starting new HTTPS connection (1): codeforces.com:443
[DEBUG] https://codeforces.com:443 "GET /enter HTTP/1.1" 302 0
[NETWORK] 302 Found
[INFO] You are logged in.
[NETWORK] GET: https://codeforces.com/contest/1454/problem/B
[DEBUG] https://codeforces.com:443 "GET /contest/1454/problem/B HTTP/1.1" 200 None
[NETWORK] 200 OK
[DEBUG] file extension: .cpp
[DEBUG] language guessing: C++
[DEBUG] all lang ids for C++: ['52', '42', '50', '54', '2', '59', '61']
[INFO] both GCC and Clang are available for C++ compiler
[INFO] use: GCC
[DEBUG] lang ids after compiler filter: ['42', '50', '54', '2', '59', '61']
[DEBUG] lang ids after version filter: ['61']
[INFO] chosen language: 61 (GNU G++17 9.2.0 (64 bit, msys 2))
[INFO] sleep(3.00)
[NETWORK] GET: https://codeforces.com/contest/1454/problem/B
[DEBUG] https://codeforces.com:443 "GET /contest/1454/problem/B HTTP/1.1" 200 None
[NETWORK] 200 OK
[DEBUG] form: <form action="?csrf_token=********************************" class="submitForm" enctype="multipart/form-data" method="post"><input name="csrf_token" type="hidden" value="********************************"/>
<input name="ftaa" type="hidden" value=""/>
<input name="bfaa" type="hidden" value=""/>
<input name="action" type="hidden" value="submitSolutionFormSubmitted"/>
<input name="submittedProblemIndex" type="hidden" value="B"/>
<input name="source" type="hidden" value=""/>
<table class="table-form" style="width:90%;">
<tr>
<td class="field">Language:</td>
<td>
<select name="programTypeId">
<option value="43">GNU GCC C11 5.1.0</option>
<option value="52">Clang++17 Diagnostics</option>
<option value="42">GNU G++11 5.1.0</option>
<option value="50">GNU G++14 6.4.0</option>
<option value="54">GNU G++17 7.3.0</option>
<option value="2">Microsoft Visual C++ 2010</option>
<option value="59">Microsoft Visual C++ 2017</option>
<option selected="selected" value="61">GNU G++17 9.2.0 (64 bit, msys 2)</option>
<option value="65">C# 8, .NET Core 3.1</option>
<option value="9">C# Mono 6.8</option>
<option value="28">D DMD32 v2.091.0</option>
<option value="32">Go 1.15.2</option>
<option value="12">Haskell GHC 8.10.1</option>
<option value="60">Java 11.0.6</option>
<option value="36">Java 1.8.0_241</option>
<option value="48">Kotlin 1.4.0</option>
<option value="19">OCaml 4.02.1</option>
<option value="3">Delphi 7</option>
<option value="4">Free Pascal 3.0.2</option>
<option value="51">PascalABC.NET 3.4.2</option>
<option value="13">Perl 5.20.1</option>
<option value="6">PHP 7.2.13</option>
<option value="7">Python 2.7.15</option>
<option value="31">Python 3.7.2</option>
<option value="40">PyPy 2.7 (7.2.0)</option>
<option value="41">PyPy 3.6 (7.2.0)</option>
<option value="8">Ruby 2.7.1</option>
<option value="49">Rust 1.42.0</option>
<option value="20">Scala 2.12.8</option>
<option value="34">JavaScript V8 4.8.0</option>
<option value="55">Node.js 12.6.3</option>
</select>
</td>
</tr>
<tr style="padding: 0; margin: 0; height: 0.5rem;line-height: 1rem;">
<td style="padding: 0; margin: 0; height: 0.5rem;"></td>
<td style="padding: 0; margin: 0; height: 0.5rem;">
<span class="programTypeNotice notice small" style="position: relative; bottom:7px;"> </span>
</td>
</tr>
<tr>
<td class="field">Choose file:</td>
<td>
<input name="sourceFile" type="file" value=""/>
</td>
</tr>
<tr>
<td colspan="2">
<div style="text-align: center;">
<div style="position: relative; display: inline-block;">
<input class="submit" style="width:10em;" type="submit" value="Submit"/>
<img class="ajax-loading-gif" src="//sta.codeforces.com/s/77249/images/ajax-loading-24x24.gif" style="display:none; position: absolute; right:-24px; bottom:0;"/>
</div>
</div>
</td>
</tr>
</table>
</form>
[DEBUG] input: <input name="csrf_token" type="hidden" value="********************************"/>
[DEBUG] input: <input name="ftaa" type="hidden" value=""/>
[DEBUG] input: <input name="bfaa" type="hidden" value=""/>
[DEBUG] input: <input name="action" type="hidden" value="submitSolutionFormSubmitted"/>
[DEBUG] input: <input name="submittedProblemIndex" type="hidden" value="B"/>
[DEBUG] input: <input name="source" type="hidden" value=""/>
[DEBUG] input: <input name="sourceFile" type="file" value=""/>
[DEBUG] input: <input class="submit" style="width:10em;" type="submit" value="Submit"/>
[DEBUG] User-Agent is temporarily disabled. The old User-Agent is 'online-judge-tools/11.1.1 (+https://github.com/online-judge-tools/oj)'
[NETWORK] POST: https://codeforces.com/contest/1454/problem/B
[NETWORK] data: {'csrf_token': '********************************', 'ftaa': '', 'bfaa': '', 'action': 'submitSolutionFormSubmitted', 'submittedProblemIndex': 'B', 'source': '', 'sourceFile': '', 'programTypeId': '61'}
[DEBUG] https://codeforces.com:443 "POST /contest/1454/problem/B HTTP/1.1" 403 431
[NETWORK] 403 Forbidden
[ERROR] 403 Client Error:  for url: https://codeforces.com/contest/1454/problem/B
Traceback (most recent call last):
  File "/home/hotaru/.local/lib/python3.8/site-packages/onlinejudge/service/codeforces.py", line 389, in submit_code
    resp.raise_for_status()
  File "/home/hotaru/.local/lib/python3.8/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error:  for url: https://codeforces.com/contest/1454/problem/B
[WARNING] You may use wrong User-Agent: 'online-judge-tools/11.1.1 (+https://github.com/online-judge-tools/oj)'
[FAILURE] submission failed

OS is WSL. oj is up to date.

$ oj --version
online-judge-tools 11.1.1 (+ online-judge-api-client 10.6.0)
$ python3 --version
Python 3.8.5
peroon commented 3 years ago

hotaroonさんが書いているので書いていませんでしたが、 私もhotaroonさんと同じログです!

R1B3n-13 commented 3 years ago

My log is also the same as hotaroon.

kmyk commented 3 years ago

@hotaroon @peroon @Tard1grad3 I believe that I've fixed this bug by https://github.com/online-judge-tools/api-client/pull/125. online-judge-api-client package is updated to v6.1.0 now. Could you upgrade the package and check it again?

peroon commented 3 years ago

I upgraded and checked. same issue... I paste the log below. (csrf replaced)

$ oj s answer.cpp 
[INFO] online-judge-tools 11.1.1 (+ online-judge-api-client 10.6.1)
[INFO] read history from: /home/peroon/.cache/online-judge-tools/download-history.jsonl
[INFO] found urls in history:
https://codeforces.com/contest/1461/problem/A
[INFO] guessed problem: https://codeforces.com/contest/1461/problem/A
[INFO] problem recognized: CodeforcesProblem.from_url('https://codeforces.com/contest/1461/problem/A'): https://codeforces.com/contest/1461/problem/A
[INFO] code (5601 byte):
#ifdef LOCAL
    #define _GLIBCXX_DEBUG
    #define __clock__
#else
    #pragma GCC optimize("Ofast")
#endif
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
... (245 lines) ...
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N;_(trailing whitespace)
    cin>>N;
    while(N--)solve();
____(trailing whitespace)
    return 0;
}(no trailing newline)
[INFO] load cookie from: /home/peroon/.local/share/online-judge-tools/cookie.jar
[NETWORK] GET: https://codeforces.com/enter
[NETWORK] 302 Found
[INFO] You are logged in.
[NETWORK] GET: https://codeforces.com/contest/1461/problem/A
[NETWORK] 200 OK
[INFO] both GCC and Clang are available for C++ compiler
[INFO] use: GCC
[INFO] chosen language: 61 (GNU G++17 9.2.0 (64 bit, msys 2))
[INFO] sleep(3.00)
Are you sure? [y/N] y
[NETWORK] GET: https://codeforces.com/contest/1461/submit
[NETWORK] 200 OK
[NETWORK] POST: https://codeforces.com/contest/1461/submit?csrf_token=5d14288xxxxxxxxxxx
[NETWORK] 403 Forbidden
[ERROR] 403 Client Error:  for url: https://codeforces.com/contest/1461/submit?csrf_token=5d14288xxxxxxxxxxx 
Traceback (most recent call last):
  File "/home/peroon/.local/lib/python3.6/site-packages/onlinejudge/service/codeforces.py", line 392, in submit_code       
    resp.raise_for_status()
  File "/home/peroon/.local/lib/python3.6/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error:  for url: https://codeforces.com/contest/1461/submit?csrf_token=5d14288xxxxxxxxxxx
[WARNING] You may use wrong User-Agent: None
[ERROR] 403 Client Error:  for url: https://codeforces.com/contest/1461/submit?csrf_token=5d14288xxxxxxxxxxx 
Traceback (most recent call last):
  File "/home/peroon/.local/lib/python3.6/site-packages/onlinejudge_command/main.py", line 271, in main
    run_program(parsed, parser=parser)
  File "/home/peroon/.local/lib/python3.6/site-packages/onlinejudge_command/main.py", line 241, in run_program
    submit(args)
  File "/home/peroon/.local/lib/python3.6/site-packages/onlinejudge_command/subcommand/submit.py", line 136, in submit     
    submission = problem.submit_code(code, language_id=LanguageId(args.language), session=sess)
  File "/home/peroon/.local/lib/python3.6/site-packages/onlinejudge/service/codeforces.py", line 397, in submit_code       
    raise e
  File "/home/peroon/.local/lib/python3.6/site-packages/onlinejudge/service/codeforces.py", line 392, in submit_code       
    resp.raise_for_status()
  File "/home/peroon/.local/lib/python3.6/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error:  for url: https://codeforces.com/contest/1461/submit?csrf_token=5d14288xxxxxxxxxxx
kmyk commented 3 years ago

Thank you for checking! It seems this issue remains even with the patch at v10.6.1. I'll try to fix this once again.

kmyk commented 3 years ago

I've investigated this issue further, and finally decided to keep it broken. Please read https://github.com/online-judge-tools/api-client/issues/127. Sorry for inconvenience, and thank you for understanding.

Also, thank you @hotaroon @peroon @Tard1grad3 for helping me with debugging.