# Using OBS Websocket with Psychopy (python)

**URL:** https://discourse.psychopy.org/t/using-obs-websocket-with-psychopy-python/36172
**Category:** Coding
**Tags:** code, python3
**Created:** [August 22, 2023, 3:46pm UTC](https://discourse.psychopy.org/t/using-obs-websocket-with-psychopy-python/36172 "2023-08-22T15:46:32Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![amyhume66](https://avatars.discourse-cdn.com/v4/letter/a/cc9497/32.png) [@amyhume66](https://discourse.psychopy.org/u/amyhume66)
#### Post date: [August 22, 2023, 3:46pm UTC](https://discourse.psychopy.org/t/using-obs-websocket-with-psychopy-python/36172/1 "2023-08-22T15:46:32Z")

</div>

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   
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] #################
