从raspberrypi相机捕获图像后,我试图将图像写入浏览器客户端。运行代码后,出现此错误。
回溯(最近通话最近): 在第23行的文件“ /home/pi/Desktop/captureImage.py” connection.write(stream.read())。文件“ /usr/lib/python3.5/socket.py”,第594行,写入返回self._sock.send(b)。BrokenPipeError:[Errno 32]管道损坏 我已经看了很多帖子,但是无法调试我的代码
import picamera
import io
import socket
server_socket = socket.socket()
server_socket.bind(('192.168.137.162',8000))
server_socket.listen(1)
print("About to take a picture")
with picamera.PiCamera() as camera:
camera.resolution = (640,480)
camera.start_preview()
connection = server_socket.accept()[0].makefile('wb')
print("connecting")
try:
stream = io.BytesIO()
camera.capture(stream, 'jpeg')
stream.seek(0)
connection.write(stream.read())
stream.seek(0)
stream.truncate()
finally:
connection.close()
server_socket.close()
camera.stop_preview()
print("connection closed")
当我粘贴pi的IP地址时,它没有显示图像,并且说192.168.137.162拒绝连接。