Qt:会话管理错误:不支持指定的任何身份验证协议。在 Linux 上使用 Python 套接字时

mar*_*oda 6 python sockets qt python-3.x raspbian

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

Qt: Session management error: None of the authentication protocols specified are supported
Run Code Online (Sandbox Code Playgroud)

附加信息:我正在运行 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()
Run Code Online (Sandbox Code Playgroud)

客户:

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()
Run Code Online (Sandbox Code Playgroud)

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

mic*_*ael 5

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

\n\n

例如,

\n\n
import matplotlib.pyplot as plt\nplt.plot([i for i in range(10)])\nplt.show()\n
Run Code Online (Sandbox Code Playgroud)\n\n

生成错误(即使它仍然显示绘图):

\n\n
Qt: Session management error: None of the authentication protocols specified are supported\n
Run Code Online (Sandbox Code Playgroud)\n\n

在没有环境变量 SESSION_MANAGER 的情况下启动pycharm会导致错误不发生 \xe2\x80\x94 要么取消设置它 ( unset SESSION_MANAGER),要么取消设置它只是为了启动程序(例如,python3pycharm等):

\n\n
env -u SESSION_MANAGER pycharm-community\n
Run Code Online (Sandbox Code Playgroud)\n