Closed hotarunw closed 3 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?)
I could reproduce the issue, but the precise condition is still unknown. My observations are:
~/.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.
requests/2.24.0
, successonline-judge-tools/11.1.1 (+https://github.com/online-judge-tools/oj)
, successonline-judge-tools/11.1.1 (+https://github.com/online-judge-tools/oj)
, failureMozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
, failureI 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.
同じ問題が私にも今起こりました。ojは最新です。
提出用formタグを見てみるとcsrf_tokenが設定されているようで、 一方ojのcodeforces.pyにはその記述はありません。
これは関係ないでしょうか? (的はずれな指摘でしたらすみません・・・)
The issue remains after the update. :sob::sob:
Okay. I'll investigate this issue again :bow:
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!
@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
hotaroonさんが書いているので書いていませんでしたが、 私もhotaroonさんと同じログです!
My log is also the same as hotaroon.
@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?
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
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.
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.
Description
When I try to submit to Codeforces, it receives wrong User-Agent error message and this 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 ```Environment
Ubuntu under Windows Subsystem for Linux
Windows
WSL
Python and oj
Other notes