Opencv and gstreamer from python - how to catch gstreamer warnings from cv2.VideoWriter()?

In python (Raspberry Pi Linux) I am generating an rtsp stream with frames from a camera and writing this to a local instance of rtsp_simple_server using cv2.VideoWriter().
This works fine actually.

However, if for some reason the rtsp_simple_server is not running then I get errors “Error pushing buffer to GStreamer pipeline” in the debugger IDE.
This is fine, but how do I catch this error inside python? Because in such cases I want to restart the system, but for that I have to first detect the error/warning which appears to come from cap_gstreamer.cpp

I have tried enclose the call in


except Exception:

but this does not detect the warning/error.
Hope for some hints from this forum. Thanks

Here is the essential code

    launch = \
        f' appsrc ' + \
        f' ! video/x-raw,format=(string)BGR,is_live=true,size={IMAGE_WIDTH * IMAGE_HEIGHT},' \
        f' stream_type=0,width={IMAGE_WIDTH},height={IMAGE_HEIGHT},framerate={FPS}/1,latency=100 ' + \
        f' ! videoconvert' + \
        f' ! v4l2h264enc ' + \
        f' ! rtspclientsink protocols=udp location=rtsp://'

    rtsp_writer = cv2.VideoWriter(launch, cv2.CAP_GSTREAMER, 0, FPS, (IMAGE_WIDTH, IMAGE_HEIGHT),   isColor=True) 

rtsp_writer.write(img_BGR) # Write to local rtsp server

and here is the error string displayed in the debugger:
[ WARN:0@18.617] global /home/heel/Opencv/opencv/modules/videoio/src/cap_gstreamer.cpp (2300) writeFrame OpenCV | GStreamer warning: Error pushing buffer to GStreamer pipeline

Finally the cv2.getBuildInformation()=
General configuration for OpenCV 4.6.0-dev =====================================
Version control: 4.6.0-319-g04ebedb6f0

Timestamp: 2022-09-24T22:47:28Z
Host: Linux 5.15.61-v8+ aarch64
CMake: 3.18.4
CMake generator: Unix Makefiles
CMake build tool: /usr/bin/gmake
Configuration: Release

CPU/HW features:
Baseline: NEON FP16

Built as dynamic libs?: YES
C++ standard: 11
C++ Compiler: /usr/bin/c++ (ver 10.2.1)
C++ flags (Release): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
C Compiler: /usr/bin/cc
C flags (Release): -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release): -Wl,–gc-sections -Wl,–as-needed -Wl,–no-undefined
Linker flags (Debug): -Wl,–gc-sections -Wl,–as-needed -Wl,–no-undefined
ccache: NO
Precompiled headers: NO
Extra dependencies: dl m pthread rt
3rdparty dependencies:

OpenCV modules:
To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching ts video videoio
Disabled: world
Disabled by dependency: -
Unavailable: java python2
Applications: tests perf_tests examples apps
Documentation: NO
Non-free algorithms: NO

GTK+: YES (ver 2.24.33)
GThread : YES (ver 2.66.8)
GtkGlExt: NO
VTK support: NO

Media I/O:
ZLib: /usr/lib/aarch64-linux-gnu/ (ver 1.2.11)
JPEG: /usr/lib/aarch64-linux-gnu/ (ver 62)
WEBP: build (ver encoder: 0x020f)
PNG: build (ver 1.6.37)
TIFF: build (ver 42 - 4.2.0)
JPEG 2000: build (ver 2.4.0)
OpenEXR: /usr/lib/aarch64-linux-gnu/ /usr/lib/aarch64-linux-gnu/ /usr/lib/aarch64-linux-gnu/ /usr/lib/aarch64-linux-gnu/ /usr/lib/aarch64-linux-gnu/ (ver 2_5)

Video I/O:
DC1394: YES (2.2.6)
avcodec: YES (58.91.100)
avformat: YES (58.45.100)
avutil: YES (56.51.100)
swscale: YES (5.7.100)
avresample: NO
GStreamer: YES (1.18.4)
Aravis SDK: YES (0.8.22)
v4l/v4l2: YES (linux/videodev2.h)

Parallel framework: pthreads

Trace: YES (with Intel ITT)

Other third-party libraries:
Lapack: NO
Eigen: NO
Custom HAL: YES (carotene (ver 0.0.1))
Protobuf: build (3.19.1)

OpenCL: YES (no extra features)
Include path: /home/heel/Opencv/opencv/3rdparty/include/opencl/1.2
Link libraries: Dynamic load

Python 3:
Interpreter: /usr/bin/python3 (ver 3.9.2)
Libraries: /usr/lib/aarch64-linux-gnu/ (ver 3.9.2)
numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.19.5)
install path: lib/python3.9/site-packages/cv2/python-3.9

Python (for build): /usr/bin/python3

ant: /bin/ant (ver 1.10.9)
Java wrappers: NO
Java tests: NO

Install to: /usr/local