Error [tcp @ 0x27a4a00] Port missing in uri

I am using OpenCV with Python to transmit an IP camera in the browser with Flask.

In Local works very well, but on the Web server with Apache (Ubuntu 18.04) I receive an error: [tcp @ 0x27a4a00] Port missing in uri

I am using this code:

index.html (Under directory ‘templates’ of Flask)

    <title>RTSP web streaming</title>
    <h1>RTSP web streaming</h1>
    <h3>XND-6080RV (ip:</h3>
    <h4>python --ip <host ip> --port <host port></h4>
    <img src="{{ url_for('video_feed') }}">

# import the necessary packages
from flask import Response, Flask, render_template
import threading
import argparse 
import datetime, time
import imutils
import cv2

# initialize the output frame and a lock used to ensure thread-safe
# exchanges of the output frames (useful when multiple browsers/tabs are viewing the stream)
outputFrame = None
lock = threading.Lock()
# initialize a flask object
app = Flask(__name__)
username = "MYUSER"
password = "MYPASS"
ip = "MYIP"
port = "MYPORT"
rtsp_url = f"rtsp://{username}:bakcAse4#@@{ip}:{port}/cam/realmonitor?channel=1&subtype=0"
source = rtsp_url

cap = cv2.VideoCapture(source)

def index():
    # return the rendered template
    return render_template("index.html")

def stream(frameCount):
    global outputFrame, lock
    if cap.isOpened():
        # cv2.namedWindow(('IP camera DEMO'), cv2.WINDOW_AUTOSIZE)
        while True:
            ret_val, frame =
            if frame.shape:
                frame = cv2.resize(frame, (640,360))
                with lock:
                    outputFrame = frame.copy()
        print('camera open failed')

def generate():
    # grab global references to the output frame and lock variables
    global outputFrame, lock
    # loop over frames from the output stream
    while True:
        # wait until the lock is acquired
        with lock:
            # check if the output frame is available, otherwise skip
            # the iteration of the loop
            if outputFrame is None:
            # encode the frame in JPEG format
            (flag, encodedImage) = cv2.imencode(".jpg", outputFrame)
            # ensure the frame was successfully encoded
            if not flag:
        # yield the output frame in the byte format
        yield(b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' + 
            bytearray(encodedImage) + b'\r\n')

def video_feed():
    # return the response generated along with the specific media
    # type (mime type)
    return Response(generate(),
        mimetype = "multipart/x-mixed-replace; boundary=frame")

# check to see if this is the main thread of execution
if __name__ == '__main__':
    # construct the argument parser and parse command line arguments
    ap = argparse.ArgumentParser()
    ap.add_argument("-i", "--ip", type=str, required=False, default='',
        help="ip address of the device")
    ap.add_argument("-o", "--port", type=int, required=False, default=8000, 
        help="ephemeral port number of the server (1024 to 65535)")
    ap.add_argument("-f", "--frame-count", type=int, default=32,
        help="# of frames used to construct the background model")
    args = vars(ap.parse_args())

    t = threading.Thread(target=stream, args=(args["frame_count"],))
    t.daemon = True
    # start the flask app["ip"], port=args["port"], debug=True,
        threaded=True, use_reloader=False)
# release the video stream pointer

I repeat: In a local port Since my Raspberry Pi works perfectly the transmission, but, on the AWS Ubuntu Web server 18.04 the rest of the Python / Flask program works well minus the transmission. The transmission is loading and does not show anything, and in console, I put that error.

always put full error message (starting at word “Traceback”) in question.
There are other useful information.

You could also print url which code uses on server - to check if it has PORT.

And last think: some servers may block access to external resource - to block spamers/hackers/bots.


If you use IP to access camera then it will not work.
It is IP in LAN (Local Area Network) and it can’t be accessed from Internet.

1 Like

I already solved this problem. The password had #@ at the end and apparently OpenCV did not distinguish between the pass and the port interception (pass@ip). Solution: remove # @ from password.