Elektordi / obs-websocket-py

Python library to communicate with an obs-websocket server (for OBS Studio)
MIT License
235 stars 59 forks source link

KeyError: 'status' with OBS 29 and obs-websocket-py 0.5.3 #83

Closed T-vK closed 1 year ago

T-vK commented 1 year ago

obs-websocket-py version: 0.5.3 OBS Studio version: 29.0.2 OS: Linux (Fedora)

When trying to connect I get this error: KeyError: 'status':

INFO:obswebsocket.core:Connecting...
INFO:obswebsocket.core:Connected!
Traceback (most recent call last):
  File "/home/fedora/test/./obs.py", line 21, in <module>
    ws.connect()
  File "/home/fedora/.local/lib/python3.10/site-packages/obswebsocket/core.py", line 70, in connect
    self._auth(self.password)
  File "/home/fedora/.local/lib/python3.10/site-packages/obswebsocket/core.py", line 116, in _auth
    if result['status'] != 'ok':
KeyError: 'status'

As #77 and #81 have been closed, I am assuming that I don't need the ´4.9.1-compat´ anymore. Correct?

iarspider commented 1 year ago

Wrong: "obs-websocket-py version: 0.5.3" only works with obs-websocket 4.9.1-compat. There is no released version (yet) that works with obs-websocket 5. You can try installing obs-websocket-py from git, but I have no idea how feature-complete that version is:

pip install git+https://github.com/Elektordi/obs-websocket-py.git@master
T-vK commented 1 year ago

I see, thanks!

I was able to successfully connect now, but I keep getting Your request type is not valid messages:

DEBUG:obswebsocket.core:Got answer for id 1: {'d': {'requestId': '1', 'requestStatus': {'code': 204, 'comment': 'Your request type is not valid.', 'result': False}, 'requestType': 'StopRecording'}, 'op': 7}

Any ideas why? Is that what you meant by "not feature-complete"?

I was using this script btw:

#!/usr/bin/env python3

import sys
import time

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

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

host = "localhost"
port = 4455
password = "secret"

def on_recording_stopped(recordingFilename):
    print("File recorded {}".format(recordingFilename))

ws = obsws(host, port, password)
ws.register(on_recording_stopped, events.RecordingStopped)
ws.connect()

try:
    print("OK")
    ws.call(requests.StopRecording())
    time.sleep(10)
    print("END")

except KeyboardInterrupt:
    pass

ws.disconnect()
T-vK commented 1 year ago

Okay... I finally got it to work. Seems like everything got renamed. RecordingStopped is now RecordStateChanged and StopRecording is now StopRecord...

#!/usr/bin/env python3

import sys
import time

#import logging
#logging.basicConfig(level=logging.DEBUG)

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

host = "localhost"
port = 4455
password = "secret"

def on_recording_state_change(event):
    outputState = event.datain.get('outputState')
    if outputState == 'OBS_WEBSOCKET_OUTPUT_STOPPED':
        recordedFilename = event.datain.get('outputPath')
        print(recordedFilename)

ws = obsws(host, port, password)
ws.register(on_recording_state_change, events.RecordStateChanged)
ws.connect()

try:
    print("OK")
    ws.call(requests.StopRecord())
    time.sleep(10)
    print("END")

except KeyboardInterrupt:
    pass

ws.disconnect()
Elektordi commented 1 year ago

Yes, they changed all names when switching the protocol to v5! I'm happy to know you was able to test the new version, and it worked. Thanks.