Obswebsocket - Error

Hey guys,
I’m tryng to use obs websocket with this simple code

import sys
import time

import logging
logging.basicConfig(level=logging.INFO)

sys.path.append('../')
from obswebsocket import obsws, events  # noqa: E402

host = "xxxxxxxxxxxxxx"
port = 4445
password = "xxxxxxxxxxxxxxxxxxxxx"


def on_event(message):
    print(u"Got message: {}".format(message))


def on_switch(message):
    print(u"You changed the scene to {}".format(message.getSceneName()))


ws = obsws(host, port, password)
ws.register(on_event)
ws.register(on_switch, events.SwitchScenes)
ws.connect()

try:
    print("OK")
    time.sleep(10)
    print("END")

except KeyboardInterrupt:
    pass

ws.disconnect()

but it give me this error

INFO:obswebsocket.core:Connecting…
INFO:obswebsocket.core:Connected!
Traceback (most recent call last):
File “C:\Users\Denis\PycharmProjects\pythonProject\OBS.py”, line 26, in
ws.connect()
File “C:\Users\Denis\PycharmProjects\venv\lib\site-packages\obswebsocket\core.py”, line 70, in connect
self._auth(self.password)
File “C:\Users\Denis\PycharmProjects\venv\lib\site-packages\obswebsocket\core.py”, line 116, in _auth
if result[‘status’] != ‘ok’:
KeyError: ‘status’

can someone help me please?
Thanks

OBS WebSocket has two different protocol versions - v4 which is available on all versions of OBS but requires a plugin, and v5 which requires OBS 28.0 or newer, but is a core feature that just has to be enabled. Which one are you using, and which one is your client library designed for? The use of port 4445 is a little unclear here, as the default port numbers are 4444 and 4455, so you could have changed either of them.

Also - which websocket connection package is this? There are several of them on PyPI.

Dear @Rosuav I try to reply.
I have OBS 28.1.2 version.
I vave installed in PyCharm obs-websocket-py version 0.5.3
The port number… I try to change it but it gave me the same error.
What do you mean with “is a core feature that just has to be enabled”?
Thanks

OBS-WebSocket has historically been a plugin that has to be installed. With OBS v28, this was brought into the core of OBS Studio, which means that everyone has it available without needing to install anything. However, the version that you get with OBS 28 isn’t compatible with older clients. The package you installed seems to be this one, which uses the older protocol.

To get things working, you’re going to need to do one of two things:

  1. Change your obs-websocket module to something that uses the newer protocol
  2. Install the OBS-WebSocket-4.x-compat package, which will give you a second websocket available on port 4444 using the older protocol.

Since this looks like a new project for you, I recommend changing to the newer protocol. Look for one that has a more recent release date (the one you’re using pushed its update in 2020) for the best odds of it supporting the newer protocol, but ideally, find something in the documentation that says what it supports.

Dear @Rosuav sorry if I ask you something else but I’m new in obs websocket.
How can I find the newer protocol you speak about?And How Have I to use it in PyCharm?
Thanks

Ask me all the questions you like about OBS Websocket - I love working with Python and I love working with OBS!

PyCharm should be irrelevant. Look for a different module on PyPI and find one that supports the newer protocol. I had a quick look and there are some that do.

Ok, thanks.
Can you suggest me one please?
But How can I import it in the PyCharm packages if I don’t find it in the standard PyCharm repository?
Thanks

You’ll have to do your own research - nobody knows your needs better than you do. I don’t know anything about the “standard PyCharm repository”, but look on PyPI.

You are right ! This is the best teach model!!I try by myself…

Dear @Rosuav at last it seems it’s working correctly!
This is my simple start code

import time
import obsws_python as obs
cl = obs.ReqClient(host='xxxxxxxxxxxxxxxxx', port=4455, password='xxxxxxxxxxxxxxxx')
time.sleep(10)

Before I have installed

obsws_python

package.
Now I’d like to start! Can you suggest me where I can find documentattion or a great tutorial for learn the main functions for open/change scenes in obs via python code?
Thanks

Great! Looks like you’re set up with a working connection there. For specifics on using that package, look at its own documentation. You should be able to find that from the same place that you found the package itself.

As to what you can do with the OBS websocket connection… here, have a browse!

I’d particularly recommend looking at the “Requests” section, which is things you can ask OBS to do, and then the “Events” section, which is things OBS will tell you about. After that, it’s entirely up to you and your imagination - what kind of dance will you make OBS do?

Tie this in with some other API and you can make all kinds of things happen. You could make a music player that sends a thing to OBS every time it moves to a new track, or a Twitch channel point redemption that changes which scene OBS is showing, or even build a complete remote control, using nothing but that websocket connection. Have fun with it!

Thankyou @Rosuav … now I try… All the best

Dear @Rosuav here me again!
This morning I tried this code

cl = obs.ReqClient(host='xxxxxxxxxxxxx', port=4455, password='xxxxxxxxxxxx')
cl.set_current_program_scene("Scena 2")

and it worked! It changed the scena to “Scena 2”.
Now my difficult is that I can’t find examples or documentation about how to write other functions like this (ex. create a new scena, transition from scene, ecc).
I saw the documentations you linked me but I didn’t find the syntax of these functions.
Can you help me with for find a sample or great video tutorial?
Thanks for your help.

Cool, glad that’s working! But honestly, the best thing to do will be to look at the documentation for the package you installed. The package contains some samples; I’d recommend you look at them.

Hi @Rosuav,

I have a different issue here, I can get all the methods working but I cannot store these responses in a variable or anything. It just allows me to log the response in the terminal.

Are you aware of any method to read these responses?

Thank you for your help

Post your code! :slight_smile:

hey chris can you help. im also having the same issue

I’ll offer the same suggestion: post your code! :slight_smile: