Aakash9518's blog

By Aakash9518, 6 weeks ago, In English

I am working on a REST API to submit your code directly on codeforces. Just wanted to know if it is useful for the community.

Rough API details

Parameter Description

1.problemID (Required) : Id of the problem. Eg- 123a is the id of the problem /contest/1447/problem/A

2.code (Required) : C++ code

3.handle (Required) : codeforces handle

4.pass (Required) : codeforces password

Since providing your handle and pass to an unknown API isn't a good practice, I would probably open source this API. Let me know what are your thoughts on this.

  • Vote: I like it
  • +2
  • Vote: I do not like it

6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I actually worked on something like that but mocking network calls which happen when you submit a solution were pretty complicated so I had to use a headlesss browser to submit the solution, which is slow. Anyways, I'm looking forward to your implementation.

  • »
    6 weeks ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    I have figured out a way to do it efficiently. The API takes around 6-7 secs to submit the code Image

6 weeks ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

I just solved this problem using any query library.

This is my program. login submit

Examples: xalanq/cf-tool endiliey/idne

There are many examples if you use search.

CF uses csrf_token. It's very easy to get around. You also need to use one session and a header (this works for me)

        "User-Agent": "python-requests/2.25.1",
        "Accept-Encoding": "gzip, deflate",
        "Accept": "*/*",
        "Connection": "keep-alive",


First, you need to perform authorization (post request).

resp = session.post( "https://codeforces.com/enter", data={ "csrf_token": get_token(session.get("https://codeforces.com/enter").text), "handleOrEmail": handle, "password": password, "remember": "on", "action": "enter", }, )

Send the solution by post request.

resp = session.get("https://codeforces.com/contest/1480/submit")
token = get_token(resp.text) # Here is the receipt of another token

data = {
    "csrf_token": token,
    "action": "submitSolutionFormSubmitted",
    "submittedProblemIndex": submittedProblemIndex,
    "contestId": contestId,
    "programTypeId": programTypeId,
    "tabSize": 4,
    "source": self.source.toPlainText(),
    "sourceCodeConfirmed": "true",

r = session.post(
    "https://codeforces.com/contest/1480/submit?csrf_token=" + token, data=data