I’m desperate, I’ve been trying to change scenes through obswebsocket with python for 2 days and I’m not able to.
The problem is that it connects to ows but it seems as if the methods I’m trying to use don’t exist… I don’t know what could be causing it. I have tried putting a print every second and running it in the terminal each print appears as a contact with obs.
On the other hand, it only activates in obs when I run it through a terminal, and then it appears connected in the obswebsocket tab…
My version of obs is 29, and I have mac version Catalina and the version of python is 3.8
I don’t know if you can tell me something… I don’t know what to do…
[Side note: Don’t use an old thread for an unrelated question. Start a new thread. @moderators can you split this off please, my message and the one that it’s a reply to?]
The first step is saying hello. Literally - the server will greet you with opcode zero, “Hello”. Are you seeing that, and if so, what’s in that message?
If you are NOT seeing the Hello message, something’s wrong in your websocket handling, nothing to do with OBS at all. Post your code and we can try to help with that.
But if you are, the next question is: what version is it announcing, and what version were you expecting to get?
Thank you very much for the response. I managed to change the scene. But I’m still having problems accessing the methods. I don’t know what they are exactly and there are things I can’t achieve.
Now I’m trying to access the scene name via “GetCurrentProgramScene” and then trying to access the name via .sceneName(). But it gives me an error. If I print what “GetCurrentProgramScene” returns, the name of the scene appears in a dictionary "<GetCurrentProgramScene request ({}) called: success ({‘currentProgramSceneName’: ‘Test’})>
"
However, I don’t know how to access it. The version that I have installed of obswebsocket on my computer is 1
On the other hand, is there an extension for visual code that has the obswebsocket methods and thus has the suggestion of the methods etc?
I hope everything is not explained in a messy way, and it is not necessary to open a new thread to ask these things.
Thank you very much indeed!
from obswebsocket import obsws, requests
import time
# Configurar la conexión
host = "localhost"
port = 4455 # Asegúrate de que este sea el puerto correcto en OBS
password =
# Lista de escenas a las que cambiar
scenes = ["PruebaTest", "Prueba"] # Reemplaza con los nombres de tus escenas
count = 0
def main():
ws = obsws(host, port, password)
try:
ws.connect()
print("Conectado a OBS WebSocket")
while True:
try:
global count
# Obtener la lista de escenas
#response = ws.call(requests.GetSceneList())
print("antes")
reponse = ws.call(requests.SetCurrentProgramScene(sceneName = scenes[count]))
#scenes = response.getScenes()
if(count == 0):
count = 1
else:
count = 0
reponse = ws.call(requests.GetCurrentProgramScene())
rn = reponse.data()
print(reponse)
time.sleep(5)
except Exception as e:
print(f"Error al cambiar a la escena {scenes[count]}: {e}")
except KeyboardInterrupt:
ws.disconnect()
if __name__ == "__main__":
main()
When use GetVersion() for list all method, I see this
Your password is leaked, go change it Although it’s probably not a huge issue if the server only listens on localhost, but still, it’s safer to hide your password when sharing your code.
The documentation for the websocket protocol is here:
That’s where you can list all available calls; the Python module will be a thin wrapper around that. I don’t know about a VS Code extension for that though.
The important version numbers are the ones from the original “Hello” message. What does ws.connect() return? Maybe that would tell you. Otherwise, look at the documentation (what you linked as “Home-page”) - there’s an example of an explicit GetVersion call that would be helpful there.
You are right, thank you…!! The ws.conect() returns none. I got the scene name this way, but I don’t know if there are better options. I don’t quite understand why it is so complex to access the request fields. There is something I’m not quite understanding.
Thank you very much for the real answers.
response = ws.call(requests.GetCurrentProgramScene())
name = response.datain.get('currentProgramSceneName')```
Hmm, this is getting into details of the specific wrapper module so I’m less fluent in it (I use OBS Websockets from a variety of different environments, so I generally think more about the actual websocket messages than the particular API). It seems that there are .getXYZ() methods for all the things you’d want to look up, so for example it should be name = response.getCurrentProgramSceneName() but you can check the examples in the repository for more details.
Hopefully that’s enough to get you where you need to go.