RobotStudio event

POST and PUT Syntax in Python

Hello Everyone,

I'm currently working on a project combining generating RAPID code with ChatGPT and sending it via Robot Web Services to GoFa.
I'm working in Python.

So far I've been able to establish connection and use GET method correctly.
However I receive Forbidden Request errors(403) while trying to use POST.

Also I'm looking for PUT Syntax(especially for Uploading a file) since "Execute" button doesn't seem to work correctly on DeveloperCenter site:
https://developercenter.robotstudio.com/api/RWS

Here's my code so far.
Could You please let me know what's wrong with it?

from aiohttp.hdrs import CONTENT_TYPE
from requests.auth import HTTPBasicAuth
import logging
import requests
import json

# Konfiguracja autoryzacji
basic_auth = HTTPBasicAuth("Default User", "robotics")

# Ustawienie formatowania logów
FORMAT = '%(asctime)-15s%(message)s'
logging.basicConfig(format=FORMAT, level=logging.DEBUG)
logger = logging.getLogger('RWS')

# Nagłówki
get_headers = {'Accept': 'application/hal+json;v=2.0'}
post_headers = {'Accept': 'application/json',
'Content-Type':'application/x-www-form-urlencoded;v=2.0'}


# Funkcja do wykonywania zapytań HTTP
def send_request(conn, method, uri, headers=None, data=None, proto='https://', host='192.168.125.1:443'):
url = f"{proto}{host}{uri}"
try:
# Wykonanie żądania HTTP
resp = conn.request(method, url, auth=basic_auth, headers=headers, data=data, verify=False)
logger.info(f"{method} {url} - Status Code: {resp.status_code}")
if resp.status_code == 200:
logger.info(f"Response: {resp.json()}")
else:
logger.error(f"Error: Failed to access URI '{uri}', Status Code: {resp.status_code}")
return resp
except Exception as e:
# Logowanie błędów
logger.error(f"Error: {e}")
return None

if __name__ == '__main__':
# Utworzenie sesji
conn = requests.Session()
conn.cookies.clear() # Upewnienie się, że ciasteczka są czyste przed logowaniem

# Wykonanie żądania GET
send_request(conn, 'GET', '/ctrl/clock', headers=get_headers)

# Wykonanie żądania POST
send_request(conn, 'POST', '/rw/rapid/execution/resetpp?mastership=explicit', headers=post_headers)

# Zamknięcie sesji
conn.close()