I am using python sockets to send characters and receive a video stream from a Raspberry PI on py LAN. So far, everything works as intended. The videostream is being received from the pi and displayed on the PC. But I get an error whenever the PI connects to my PC (the PC is the server and the PI is the client). The error is:
Qt: Session management error: None of the authentication protocols specified are supported
Additional info: I am running Ubuntu 19.10. My python version is 3.7. Attached below are both the server file and the client file.
import io
import socket
import struct
import cv2
import numpy as np
class Server:
opened = False
address = ''
port = 0
clientSocket = None
connection = None
socketServer = socket.socket()
def __init__(self, address, port):
self.address = address
self.port = port
def connect(self):
try:
self.socketServer = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socketServer.bind((self.address, self.port)) # ADD IP HERE
print("Server: Opened and awaiting stream")
except: print("Server: Failed to open StreamCollector")
try:
self.socketServer.listen(0)
# self.clientSocket = self.socketServer.accept()[0].makefile('rb')
self.clientSocket, address = self.socketServer.accept()
self.connection = self.clientSocket.makefile('rb')
self.opened = True
print(f"Stream Initialized from {address}")
except:
self.close()
print("Server: No stream was found")
def getStreamImage(self):
img = None
try:
image_len = struct.unpack('<L', self.connection.read(struct.calcsize('<L')))[0]
imageStream = io.BytesIO()
imageStream.write(self.connection.read(image_len))
imageStream.seek(0)
imageBytes = np.asarray(bytearray(imageStream.read()), dtype=np.uint8)
img = cv2.imdecode(imageBytes, cv2.IMREAD_GRAYSCALE)
except:
self.close()
print("Server: Stream halted")
return img
def sendCommand(self, command):
self.clientSocket.send(bytes(command, "ascii"))
def close(self):
try:
if self.clientSocket is not None:
self.clientSocket.close()
if self.connection is not None:
self.connection.close()
self.socketServer.close()
self.opened = False
print("Server: Closed")
except: print("Server: Failed to close")
def isOpened(self):
return self.opened
if __name__ == '__main__':
host, port = '10.78.1.195', 8000
# host, port = '10.17.26.78', 8000
server = Server(host, port)
server.connect()
while server.isOpened():
img = server.getStreamImage()
cv2.imshow("stream", img)
if cv2.waitKey(1) == ord('q'): server.close()
Client:
import io
import socket
import struct
import time
import picamera
# create socket and bind host
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('10.78.1.195', 8000))
connection = client_socket.makefile('wb')
try:
with picamera.PiCamera() as camera:
camera.resolution = (320, 240) # pi camera resolution
camera.framerate = 15 # 15 frames/sec
start = time.time()
stream = io.BytesIO()
# send jpeg format video stream
for foo in camera.capture_continuous(stream, 'jpeg', use_video_port=True):
connection.write(struct.pack('<L', stream.tell()))
connection.flush()
stream.seek(0)
connection.write(stream.read())
if time.time() - start > 600:
break
stream.seek(0)
stream.truncate()
connection.write(struct.pack('<L', 0))
finally:
connection.close()
client_socket.close()
If I can provide any additional information please let me know.
Perhaps this may help, although it's not exactly the same situation. I've gotten the same error when using matplotlib
to display a plot running inside pycharm IDE, so it's possible the error could be coming from cv2.imshow("stream", img)
.
For example,
import matplotlib.pyplot as plt
plt.plot([i for i in range(10)])
plt.show()
Generates error (even though it still shows the plot):
Qt: Session management error: None of the authentication protocols specified are supported
Starting pycharm
without the env variable SESSION_MANAGER causes the error to not occur — either unset it (unset SESSION_MANAGER
), or unset it just to launch the program (eg, python3
, pycharm
, etc):
env -u SESSION_MANAGER pycharm-community
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With