Qt: Session management error: None of the authentication protocols specified are supported. When using Python sockets on Linux

Qt: Session management error: None of the authentication protocols specified are supported. When using Python sockets on Linux

我正在使用 python 套接字从 py LAN 上的 Raspberry PI 发送字符和接收视频流。到目前为止,一切都按预期进行。正在从 pi 接收视频流并显示在 PC 上。但是每当 PI 连接到我的 PC 时,我都会收到错误消息(PC 是服务器,PI 是客户端)。错误是:

Qt: Session management error: None of the authentication protocols specified are supported

附加信息: 我是 运行 Ubuntu 19.10。我的 python 版本是 3.7。下面附上服务器文件和客户端文件。

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()

客户:

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()

如果我可以提供任何其他信息,请告诉我。

也许这可能会有所帮助,尽管情况并不完全相同。我在使用 matplotlib 在 pycharm IDE 中显示图 运行 时遇到了同样的错误,所以错误可能来自 cv2.imshow("stream", img)

例如,

import matplotlib.pyplot as plt
plt.plot([i for i in range(10)])
plt.show()

产生错误(即使它仍然显示情节):

Qt: Session management error: None of the authentication protocols specified are supported

在没有 env 变量 SESSION_MANAGER 的情况下启动 pycharm 会导致错误不会发生 — 取消设置 (unset SESSION_MANAGER),或者取消设置只是为了启动程序(例如,python3, pycharm, 等等):

env -u SESSION_MANAGER pycharm-community

运行 这个命令

unset SESSION_MANAGER