DOMjudge / domjudge

DOMjudge programming contest jury system
https://www.domjudge.org
GNU General Public License v2.0
712 stars 250 forks source link

How to use the API for adding a new submission? #2357

Closed as6325400 closed 6 months ago

as6325400 commented 6 months ago

I attempted to upload the code via the API but received a 401 response.

I have added roles for API reader and API writer 截圖 2024-03-09 下午3 45 59

import requests
import json

url = 'https://pgds.csie.io/api/v4/contests/HW03/submissions'  

data = {
    "problem_id": "careful_hero",
    "language_id": "c",
    "team_id": "3",
    "time": "2024-03-09T15:11:57.344+08:00",
    "files": [
        {
            "data": "#include<stdio.h>; int main(){printf(\"dwadwadad\");}"
        }
    ]
}

json_data = json.dumps(data)

response = requests.post(url, data=json_data, headers={'Content-Type': 'application/json'})

print(response.status_code)  
print(response.text)         

I tried to test whether the upload was successful with this piece of code, but I received a 401 response. Can you help me identify what I did wrong

eldering commented 6 months ago

Please use slack or our mailing lists to ask questions, see https://www.domjudge.org/development, this is meant for bug reports, feature requests etc.

The file contents should be base64 encoded IIRC.