Using OBS Websocket with Psychopy (python)

amyhume66

New Member
Hi there,

I'm trying to set up code components in my psychopy script that connects to OBS websocket and starts and stops recording for different routines.I've successfully ran this python code in VS code but I'm running into errors when I try and incorporate it into python. Here is my code in the begin experiment portion:

#adding libraries for OBS triggers
import sys

# Add the package directory to the Python path
package_path = r"C:\Users\IHDSC\AppData\Local\Programs\Python\Python311\Lib\site-packages"
sys.path.append(package_path)

# Set the Python interpreter explicitly
sys.executable = r"C:\Users\IHDSC\AppData\Local\Programs\Python\Python311\python.exe"
import obsws_python as obs
import subprocess

cl = obs.ReqClient(host='localhost', port=4455, subs = {}, password='mystrongpass', timeout=3)

And the error I am getting when running the psychopy script is as follows:

Traceback (most recent call last):
File "C:\Users\IHDSC\Desktop\Jumble\Jumble_lastrun.py", line 122, in <module>
cl = obs.ReqClient(host='localhost', port=4455, subs = {}, password='mystrongpass', timeout=3)
File "C:\Users\IHDSC\AppData\Local\Programs\Python\Python311\Lib\site-packages\obsws_python\reqs.py", line 21, in __init__
success = self.base_client.authenticate()
File "C:\Users\IHDSC\AppData\Local\Programs\Python\Python311\Lib\site-packages\obsws_python\baseclient.py", line 117, in authenticate
raise OBSSDKError(
obsws_python.error.OBSSDKError: failed to identify client with the server, please check connection settings
################ Experiment ended with exit code 1 [pid:13164] #################
 
Top