Python 3 IP Webcamera byte Error
Question: I am working on using Python 3 to take an IP web camera's stream and display
it on my computer. The following code only works in python 2.7

    
    
    import cv2
    import urllib.request
    import numpy as np
    
    stream=urllib.request.urlopen('http://192.168.0.90/mjpg/video.mjpg')
    bytes=''
    while True:
        bytes+=stream.read(16384)
        a = bytes.find('\xff\xd8')
        b = bytes.find('\xff\xd9')
        if a!=-1 and b!=-1:
            jpg = bytes[a:b+2]
            bytes= bytes[b+2:]
            i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.IMREAD_COLOR)
            cv2.imshow('i',i)
            if cv2.waitKey(1) ==27:
                exit(0)
    

However when I try it on Python 3 I get the following error

> bytes+=stream.read(16384)
>
> TypeError: Can't convert 'bytes' object to str implicitly

This works perfectly in 2.7 but I cannot find a way to get it to work in 3,
any ideas?


Answer: in python3 str are not single bytes

change it to

    
    
    bytes=b''
    

also bytes is a builtin ... you probably should not use that as a variable
name

