我正在使用python套接字从py局域网上的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
而不使用 env 变量 SESSION_MANAGER 则会导致错误不发生 - 或者取消设置它 (unset SESSION_MANAGER
),或者仅仅为了启动程序而取消设置(例如 python3
, pycharm
、等)。)
env -u SESSION_MANAGER pycharm-community