Cant connect to OBS

Fairly new to python.
trying to setup swapping to a random scene in OBS through Python and really struggling.
im sure im missing something easy but im going off pretty old tutorials
This is my script in Python
Ive also installed pip install obs-websocket-py in the terminal

edit: i get this error
line 15, in{“Normal”: random_scene}))
TypeError: init() takes 1 positional argument but 2 were given

import time
import random
from obswebsocket import obsws, requests

# Connect to OBS WebSocket server
ws = obsws("xxxxxx", 4455, "xxxxxxx") 

scenes = ['Scroll', 'Normal', 'clouds']

    while True:
        random_scene = random.choice(scenes){"scene-name": random_scene}))

        print(f"Switched to '{random_scene}' scene.")


except KeyboardInterrupt:
    print('Disconnected from OBS')

I’m not familiar with the obswebsocket package, but I’m assuming you mean this one?

Wha happens when you try this? Do you get any sort of exceptions?

Have you set up OBS to have the necessary password, and is it listening on the IP you expect it to be on? (Probably easiest to run everything on the same computer and use localhost, at least for initial testing.)

sorry my bad, forgot to post the error in the post, its this

line 15, in{“Normal”: random_scene}))
TypeError: init() takes 1 positional argument but 2 were given

everything password and port wised is the same and its all on the same computer

Looking at their examples, it seems they use keyword arguments, not a dictionary:

That would explain why it’s not expecting any positional arguments.

Ahhhhh i see where im going wrong
Just got it working now so that it will change to a random scene for before swapping back to my default
Not sure how pretty the coding is but as long as it works im happy
Thanks for the help really appreciate it

import sys
import time
import random

import logging

from obswebsocket import obsws, requests  # noqa: E402

host = "localhost"
port = 4455
password = "xxxxxxx"

ws = obsws(host, port, password)

    while True:
        scenes =
        random_scene = random.choice(scenes.getScenes())['sceneName']

        print("Switching to {}".format(random_scene))

        print("Switching to 'Normal'")'Normal'))

        print(f"Switched to {random_scene}")

except KeyboardInterrupt:
1 Like