python - Qt: session 管理错误:不支持指定的身份验证协议(protocol)。在 Linux 上使用 Python 套接字时

标签 python python-3.x qt sockets raspbian

我正在使用 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

开始 pycharm没有环境变量 SESSION_MANAGER 会导致错误不会发生 — 要么取消设置( unset SESSION_MANAGER ),要么取消设置只是为了启动程序(例如,python3pycharm 等):
env -u SESSION_MANAGER pycharm-community

关于python - Qt: session 管理错误:不支持指定的身份验证协议(protocol)。在 Linux 上使用 Python 套接字时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59057653/

相关文章:

Pythonlogging.getLogger 在 AWS Glue python shell 作业中不起作用

python - 如何获取另一台机器上运行的作业的状态?

python - 使用word2vec预训练向量,如何生成句子的id作为tensorflow中tf.nn.embedding_lookup函数的输入?

python - 无法导入模块 'lambda_function' : cannot import name 'WinDLL' from 'ctypes' (/var/lang/lib/python3. 7/ctypes/__init__.py

python - 用于捕获和替换模式中数字的正则表达式

c++ - Qt 5- QTextEdit 恢复为默认字体

python - 使用对数刻度注释 seaborn distplot 会引发错误

python-3.x - 基于 Condition Pandas Dataframe 拆分列数据

python - PyQt 中复选框的 ListView

c++ - 如何获取使用 QProcess 调用的程序的返回标准输出?