Elektordi / obs-websocket-py

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

requests.SetRecordDirectory takes 1 positional argument but 2 were given #88

Open REDS1736 opened 1 year ago

REDS1736 commented 1 year ago

Executing requests.SetRecordDirectory('C:/Users/REDS1736/Desktop') results in the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() takes 1 positional argument but 2 were given

I already tried giving the desired path as a keyword (requests.SetRecordDirectory(recordDirectory='C:/Users/REDS1736/Desktop'); i guessed the name of the keyword using this official piece of OBS docs: https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#setrecorddirectory), but that just gives me a new error:

<SetRecordDirectory request ({'directory': 'C:/Users/REDS1736/Desktop/'}) called: failed ({})> 

I suppose, the keyword i use is wrong but i can't find the right one.

RaphBarniques commented 1 year ago

Same here!

SetFilenameFormatting gets me a "takes 1 positional argument but 2 were given" and GetFilenameFormatting gets me a "request call failed"

Here is my code:

from obswebsocket import obsws, requests

client = obsws("localhost", 4455)
client.connect()
print(client.call(requests.GetFilenameFormatting()))
client.call(requests.SetFilenameFormatting("TESTNAME"))
print(client.call(requests.GetFilenameFormatting()))
client.call(requests.StartRecording())
client.disconnect()

Edit: Looking at the Requests Protocol sheet I managed to find the new way (v5) of formatting the request for the recording part (StartRecording -> StartRecord). Unfortunately I did not find the new way of manipulating the filename formatting. I will continue to search.

methecooldude commented 1 year ago

Also getting similar when using SetSceneItemRender (in legacy v4 mode)... Baserequests.__init__() takes 1 positional argument but 3 were given

iarspider commented 1 year ago

With the new version of obs-websocket-py you need to explicitly name parameters, e.g.:

requests.SetFilenameFormatting(**{'filename-formatting': 'TESTNAME'})

(yes, you need to use dictionary unpacking, since the key contains -) And looks like the V5 doesn't have a way to set filename formatting

iarspider commented 1 year ago

SetSceneItemRender

See keywords here: https://github.com/obsproject/obs-websocket/blob/4.x-compat/docs/generated/protocol.md#setsceneitemrender, and use the same dictionary unpacking trick.

methecooldude commented 1 year ago

SetSceneItemRender

See keywords here: https://github.com/obsproject/obs-websocket/blob/4.x-compat/docs/generated/protocol.md#setsceneitemrender, and use the same dictionary unpacking trick.

Ah, thanks. I did think a bit after commenting and some reading that it might be the parameter names... but didn't know about dictionary unpacking, so thanks for that :)

iarspider commented 1 year ago

@Elektordi would it be possible to restore the old behavior, when kwargs with _ were converted to dashed ones?