Connection test - lots of errors

I found answers here for the @-sign problem, and the except syntax, andI apologise for the huge paste, but - the port number seems to bwe ione problem - where is it set? and the rest?
mflix_venv) PS C:\mflix-python> pytest -m connection
============================= test session starts =============================
platform win32 – Python 3.6.1, pytest-3.9.1, py-1.7.0, pluggy-0.8.0
rootdir: C:\mflix-python, inifile:
plugins: flask-0.10.0
collected 35 items / 31 deselected

tests\test_db_connection.py FFFF [100%]

================================== FAILURES ===================================
______________________________ test_atlas_setup _______________________________

client = <FlaskClient <Flask ‘mflix.factory’>>
config = <Config {‘DEBUG’: False, ‘TESTING’: False, ‘PROPAGATE_EXCEPTIONS’: True, ‘PRESERVE_CONTEXT_ON_EXCEPTION’: None, 'SECRE…00001BB6DBF3268>, ‘MFLIX_DB_URI’: ‘mongodb+srv://m220student:m220password@mongodb+srv://mflix-kjykb.mongodb.net/test’}>

@pytest.mark.connection
@pytest.mark.usefixtures('config')
def test_atlas_setup(client, config):
  result = get_coll_names(config)

tests\test_db_connection.py:24:


tests\test_db_connection.py:17: in get_coll_names
db = MongoClient(config[‘MFLIX_DB_URI’])[“mflix”]
mflix_venv\lib\site-packages\pymongo\mongo_client.py:494: in init
res = uri_parser.parse_uri(entity, port, warn=True)
mflix_venv\lib\site-packages\pymongo\uri_parser.py:390: in parse_uri
nodes = split_hosts(hosts, default_port=None)
mflix_venv\lib\site-packages\pymongo\uri_parser.py:260: in split_hosts
nodes.append(parse_host(entity, port))


entity = ‘mongodb srv:’, default_port = None

def parse_host(entity, default_port=DEFAULT_PORT):
    """Validates a host string

    Returns a 2-tuple of host followed by port where port is default_port
    if it wasn't specified in the string.

    :Parameters:
        - `entity`: A host or host:port string where host could be a
                    hostname or IP address.
        - `default_port`: The port number to use when one wasn't
                          specified in entity.
    """
    host = entity
    port = default_port
    if entity[0] == '[':
        host, port = parse_ipv6_literal_host(entity, default_port)
    elif entity.endswith(".sock"):
        return entity, default_port
    elif entity.find(':') != -1:
        if entity.count(':') > 1:
            raise ValueError("Reserved characters such as ':' must be "
                             "escaped according RFC 2396. An IPv6 "
                             "address literal must be enclosed in '[' "
                             "and ']' according to RFC 2732.")
        host, port = host.split(':', 1)
    if isinstance(port, string_type):
        if not port.isdigit() or int(port) > 65535 or int(port) <= 0:
            raise ValueError("Port must be an integer between 0 and 65535: %s"
                           % (port,))

E ValueError: Port must be an integer between 0 and 65535:

mflix_venv\lib\site-packages\pymongo\uri_parser.py:155: ValueError
______________________________ test_basic_movies ______________________________

client = <FlaskClient <Flask ‘mflix.factory’>>

@pytest.mark.connection
def test_basic_movies(client):
  (actual, num_found) = get_movies({}, 0, 20)

tests\test_db_connection.py:31:


mflix\db.py:218: in get_movies
cursor = db.movies.find(query).sort(sort)
mflix_venv\lib\site-packages\werkzeug\local.py:347: in getattr
return getattr(self._get_current_object(), name)
mflix_venv\lib\site-packages\werkzeug\local.py:306: in _get_current_object
return self.__local()
mflix\db.py:46: in get_db
MFLIX_DB_URI,
mflix_venv\lib\site-packages\pymongo\mongo_client.py:494: in init
res = uri_parser.parse_uri(entity, port, warn=True)
mflix_venv\lib\site-packages\pymongo\uri_parser.py:390: in parse_uri
nodes = split_hosts(hosts, default_port=None)
mflix_venv\lib\site-packages\pymongo\uri_parser.py:260: in split_hosts
nodes.append(parse_host(entity, port))


entity = ‘mongodb srv:’, default_port = None

def parse_host(entity, default_port=DEFAULT_PORT):
    """Validates a host string

    Returns a 2-tuple of host followed by port where port is default_port
    if it wasn't specified in the string.

    :Parameters:
        - `entity`: A host or host:port string where host could be a
                    hostname or IP address.
        - `default_port`: The port number to use when one wasn't
                          specified in entity.
    """
    host = entity
    port = default_port
    if entity[0] == '[':
        host, port = parse_ipv6_literal_host(entity, default_port)
    elif entity.endswith(".sock"):
        return entity, default_port
    elif entity.find(':') != -1:
        if entity.count(':') > 1:
            raise ValueError("Reserved characters such as ':' must be "
                             "escaped according RFC 2396. An IPv6 "
                             "address literal must be enclosed in '[' "
                             "and ']' according to RFC 2732.")
        host, port = host.split(':', 1)
    if isinstance(port, string_type):
        if not port.isdigit() or int(port) > 65535 or int(port) <= 0:
            raise ValueError("Port must be an integer between 0 and 65535: %s"
                           % (port,))

E ValueError: Port must be an integer between 0 and 65535:

mflix_venv\lib\site-packages\pymongo\uri_parser.py:155: ValueError
___________________________ test_search_by_movie_id ___________________________

client = <FlaskClient <Flask ‘mflix.factory’>>

@pytest.mark.connection
def test_search_by_movie_id(client):
  actual = get_movie("573a13eff29313caabdd82f3")

tests\test_db_connection.py:38:


mflix\db.py:269: in get_movie
movie = db.movies.aggregate(pipeline).next()
mflix_venv\lib\site-packages\werkzeug\local.py:347: in getattr
return getattr(self._get_current_object(), name)
mflix_venv\lib\site-packages\werkzeug\local.py:306: in _get_current_object
return self.__local()
mflix\db.py:46: in get_db
MFLIX_DB_URI,
mflix_venv\lib\site-packages\pymongo\mongo_client.py:494: in init
res = uri_parser.parse_uri(entity, port, warn=True)
mflix_venv\lib\site-packages\pymongo\uri_parser.py:390: in parse_uri
nodes = split_hosts(hosts, default_port=None)
mflix_venv\lib\site-packages\pymongo\uri_parser.py:260: in split_hosts
nodes.append(parse_host(entity, port))


entity = ‘mongodb srv:’, default_port = None

def parse_host(entity, default_port=DEFAULT_PORT):
    """Validates a host string

    Returns a 2-tuple of host followed by port where port is default_port
    if it wasn't specified in the string.

    :Parameters:
        - `entity`: A host or host:port string where host could be a
                    hostname or IP address.
        - `default_port`: The port number to use when one wasn't
                          specified in entity.
    """
    host = entity
    port = default_port
    if entity[0] == '[':
        host, port = parse_ipv6_literal_host(entity, default_port)
    elif entity.endswith(".sock"):
        return entity, default_port
    elif entity.find(':') != -1:
        if entity.count(':') > 1:
            raise ValueError("Reserved characters such as ':' must be "
                             "escaped according RFC 2396. An IPv6 "
                             "address literal must be enclosed in '[' "
                             "and ']' according to RFC 2732.")
        host, port = host.split(':', 1)
    if isinstance(port, string_type):
        if not port.isdigit() or int(port) > 65535 or int(port) <= 0:
            raise ValueError("Port must be an integer between 0 and 65535: %s"
                           % (port,))

E ValueError: Port must be an integer between 0 and 65535:

mflix_venv\lib\site-packages\pymongo\uri_parser.py:155: ValueError
___________________________ test_simple_text_search ___________________________

client = <FlaskClient <Flask ‘mflix.factory’>>

@pytest.mark.connection
def test_simple_text_search(client):
  (actual, _) = get_movies({"$text": {"$search": "The Martian"}}, 0, 20)

tests\test_db_connection.py:44:


mflix\db.py:218: in get_movies
cursor = db.movies.find(query).sort(sort)
mflix_venv\lib\site-packages\werkzeug\local.py:347: in getattr
return getattr(self._get_current_object(), name)
mflix_venv\lib\site-packages\werkzeug\local.py:306: in _get_current_object
return self.__local()
mflix\db.py:46: in get_db
MFLIX_DB_URI,
mflix_venv\lib\site-packages\pymongo\mongo_client.py:494: in init
res = uri_parser.parse_uri(entity, port, warn=True)
mflix_venv\lib\site-packages\pymongo\uri_parser.py:390: in parse_uri
nodes = split_hosts(hosts, default_port=None)
mflix_venv\lib\site-packages\pymongo\uri_parser.py:260: in split_hosts
nodes.append(parse_host(entity, port))


entity = ‘mongodb srv:’, default_port = None

def parse_host(entity, default_port=DEFAULT_PORT):
    """Validates a host string

    Returns a 2-tuple of host followed by port where port is default_port
    if it wasn't specified in the string.

    :Parameters:
        - `entity`: A host or host:port string where host could be a
                    hostname or IP address.
        - `default_port`: The port number to use when one wasn't
                          specified in entity.
    """
    host = entity
    port = default_port
    if entity[0] == '[':
        host, port = parse_ipv6_literal_host(entity, default_port)
    elif entity.endswith(".sock"):
        return entity, default_port
    elif entity.find(':') != -1:
        if entity.count(':') > 1:
            raise ValueError("Reserved characters such as ':' must be "
                             "escaped according RFC 2396. An IPv6 "
                             "address literal must be enclosed in '[' "
                             "and ']' according to RFC 2732.")
        host, port = host.split(':', 1)
    if isinstance(port, string_type):
        if not port.isdigit() or int(port) > 65535 or int(port) <= 0:
            raise ValueError("Port must be an integer between 0 and 65535: %s"
                           % (port,))

E ValueError: Port must be an integer between 0 and 65535:

mflix_venv\lib\site-packages\pymongo\uri_parser.py:155: ValueError
============================== warnings summary ===============================
c:\mflix-python\mflix_venv\lib\site-packages\pytest_flask\plugin.py:109: RemovedInPytest4Warning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
c:\mflix-python\mflix_venv\lib\site-packages\pytest_flask\plugin.py:61: RemovedInPytest4Warning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
c:\mflix-python\mflix_venv\lib\site-packages\pytest_flask\plugin.py:78: RemovedInPytest4Warning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

c:\mflix-python\mflix_venv\lib\site-packages\pytest_flask\plugin.py:109: RemovedInPytest4Warning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
c:\mflix-python\mflix_venv\lib\site-packages\pytest_flask\plugin.py:61: RemovedInPytest4Warning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
c:\mflix-python\mflix_venv\lib\site-packages\pytest_flask\plugin.py:78: RemovedInPytest4Warning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

c:\mflix-python\mflix_venv\lib\site-packages\pytest_flask\plugin.py:109: RemovedInPytest4Warning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
c:\mflix-python\mflix_venv\lib\site-packages\pytest_flask\plugin.py:61: RemovedInPytest4Warning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
c:\mflix-python\mflix_venv\lib\site-packages\pytest_flask\plugin.py:78: RemovedInPytest4Warning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

c:\mflix-python\mflix_venv\lib\site-packages\pytest_flask\plugin.py:109: RemovedInPytest4Warning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
c:\mflix-python\mflix_venv\lib\site-packages\pytest_flask\plugin.py:61: RemovedInPytest4Warning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)
c:\mflix-python\mflix_venv\lib\site-packages\pytest_flask\plugin.py:78: RemovedInPytest4Warning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

– Docs: https://docs.pytest.org/en/latest/warnings.html
============ 4 failed, 31 deselected, 12 warnings in 0.82 seconds =============
(mflix_venv) PS C:\mflix-python> python run.py

  • Restarting with stat
  • Debugger is active!
  • Debugger PIN: 115-276-458
  • Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Hello,

I was getting this error when using the mongo shell connection string. It worked for me when I tried the Standard connection string for Application.

1 Like

I got this error. Can somebody help with it

Hello SA_47571,

Thanks for the note. It looks like you have the mflix virtual environment working, great job there.

Have you run pip install -r requirements.txt? This will install the necessary dependencies to your virtual environment.

Also, make sure your virtual environment is using Python 3.

Matt