Ticket: Connection

I am getting following error when I am working for “Ticket: Connection”.

(mflix) D:\SANJAI\university\m220\mflix-python>pytest -m connection
============================= test session starts =============================
platform win32 – Python 3.7.0, pytest-3.8.0, py-1.6.0, pluggy-0.7.1
rootdir: D:\SANJAI\university\m220\mflix-python, inifile:
plugins: remotedata-0.3.0, openfiles-0.3.0, flask-0.10.0, doctestplus-0.1.3, arraydiff-0.2
collected 43 items / 39 deselected

tests\test_db_connection.py EEEE [100%]

=================================== ERRORS ====================================
_____________________ ERROR at setup of test_atlas_setup ______________________

request = <SubRequest ‘_configure_application’ for <Function ‘test_atlas_setup’>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x0000000005267710>

@pytest.fixture(autouse=True)
def _configure_application(request, monkeypatch):
    """Use `pytest.mark.options` decorator to pass options to your application
    factory::

        @pytest.mark.options(debug=False)
        def test_something(app):
            assert not app.debug, 'the application works not in debug mode!'

    """
    if 'app' not in request.fixturenames:
        return
  app = request.getfuncargvalue('app')

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109:


tests\conftest.py:14: in app
app.config[‘SECRET_KEY’] = config[‘TEST’][‘SECRET_KEY’]


self = <configparser.ConfigParser object at 0x0000000004FE3E10>, key = ‘TEST’

def __getitem__(self, key):
    if key != self.default_section and not self.has_section(key):
      raise KeyError(key)

E KeyError: ‘TEST’

C:\ProgramData\Anaconda3\lib\configparser.py:958: KeyError
_____________________ ERROR at setup of test_basic_movies _____________________

request = <SubRequest ‘_configure_application’ for <Function ‘test_basic_movies’>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x00000000053B74E0>

@pytest.fixture(autouse=True)
def _configure_application(request, monkeypatch):
    """Use `pytest.mark.options` decorator to pass options to your application
    factory::

        @pytest.mark.options(debug=False)
        def test_something(app):
            assert not app.debug, 'the application works not in debug mode!'

    """
    if 'app' not in request.fixturenames:
        return
  app = request.getfuncargvalue('app')

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109:


tests\conftest.py:14: in app
app.config[‘SECRET_KEY’] = config[‘TEST’][‘SECRET_KEY’]


self = <configparser.ConfigParser object at 0x0000000004FE3E10>, key = ‘TEST’

def __getitem__(self, key):
    if key != self.default_section and not self.has_section(key):
      raise KeyError(key)

E KeyError: ‘TEST’

C:\ProgramData\Anaconda3\lib\configparser.py:958: KeyError
__________________ ERROR at setup of test_search_by_movie_id __________________

request = <SubRequest ‘_configure_application’ for <Function ‘test_search_by_movie_id’>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x0000000005325E10>

@pytest.fixture(autouse=True)
def _configure_application(request, monkeypatch):
    """Use `pytest.mark.options` decorator to pass options to your application
    factory::

        @pytest.mark.options(debug=False)
        def test_something(app):
            assert not app.debug, 'the application works not in debug mode!'

    """
    if 'app' not in request.fixturenames:
        return
  app = request.getfuncargvalue('app')

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109:


tests\conftest.py:14: in app
app.config[‘SECRET_KEY’] = config[‘TEST’][‘SECRET_KEY’]


self = <configparser.ConfigParser object at 0x0000000004FE3E10>, key = ‘TEST’

def __getitem__(self, key):
    if key != self.default_section and not self.has_section(key):
      raise KeyError(key)

E KeyError: ‘TEST’

C:\ProgramData\Anaconda3\lib\configparser.py:958: KeyError
__________________ ERROR at setup of test_simple_text_search __________________

request = <SubRequest ‘_configure_application’ for <Function ‘test_simple_text_search’>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x0000000005358E48>

@pytest.fixture(autouse=True)
def _configure_application(request, monkeypatch):
    """Use `pytest.mark.options` decorator to pass options to your application
    factory::

        @pytest.mark.options(debug=False)
        def test_something(app):
            assert not app.debug, 'the application works not in debug mode!'

    """
    if 'app' not in request.fixturenames:
        return
  app = request.getfuncargvalue('app')

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109:


tests\conftest.py:14: in app
app.config[‘SECRET_KEY’] = config[‘TEST’][‘SECRET_KEY’]


self = <configparser.ConfigParser object at 0x0000000004FE3E10>, key = ‘TEST’

def __getitem__(self, key):
    if key != self.default_section and not self.has_section(key):
      raise KeyError(key)

E KeyError: ‘TEST’

C:\ProgramData\Anaconda3\lib\configparser.py:958: KeyError
============================== warnings summary ===============================
C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

– Docs: https://docs.pytest.org/en/latest/warnings.html
============= 39 deselected, 4 warnings, 4 error in 1.44 seconds ==============

(mflix) D:\SANJAI\university\m220\mflix-python>python run.py
Traceback (most recent call last):
File “run.py”, line 13, in
app.config[‘MFLIX_DB_URI’] = config[‘PROD’][‘MFLIX_DB_URI’]
File “C:\ProgramData\Anaconda3\lib\configparser.py”, line 958, in getitem
raise KeyError(key)
KeyError: ‘PROD’

contents of dotini_win.ini file are pasted here

Ticket: Connection

Rename this file to .ini after filling in your MFLIX_DB_URI and your SECRET_KEY

Do not surround the URI with quotes

[PROD]
SECRET_KEY = Nakshatra
MFLIX_DB_URI = mongodb+srv://m220student:password@mflix-bagew.mongodb.net/test

[TEST]
SECRET_KEY = Sangeeta
MFLIX_DB_URI = mongodb+srv://m220student:password@mflix-bagew.mongodb.net/test

Can you please help where I am doing wrong?

Thank you,
Sanjai

I am getting the same error and would appreciate any help!

I have no idea what’s going on with your first post’s layout. It’s illegible to me.

Could you please edit it and paste all your logs inside a codeblock? You can make a code block by making a line with three back-ticks, then pasting the output, then three back-ticks again. For example:

```
This is a code block
```

EDIT :
The four warnings are fine, ignore them. The four errors are a different matter.

1 Like

Thank you.

When I am executing unit tests for ‘Ticket: Connection’, output log is pasted here.

…Input Code…
(mflix) D:\SANJAI\university\m220\mflix-python>pytest -m connection

…Output Log…

============================= test session starts =============================
platform win32 – Python 3.7.0, pytest-3.8.0, py-1.6.0, pluggy-0.7.1
rootdir: D:\SANJAI\university\m220\mflix-python, inifile:
plugins: remotedata-0.3.0, openfiles-0.3.0, flask-0.10.0, doctestplus-0.1.3, arraydiff-0.2
collected 43 items / 39 deselected

tests\test_db_connection.py EEEE [100%]

=================================== ERRORS ====================================
_____________________ ERROR at setup of test_atlas_setup ______________________

request = <SubRequest ‘_configure_application’ for <Function ‘test_atlas_setup’>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x0000000005267710>

@pytest.fixture(autouse=True)
def _configure_application(request, monkeypatch):
    """Use `pytest.mark.options` decorator to pass options to your application
    factory::

        @pytest.mark.options(debug=False)
        def test_something(app):
            assert not app.debug, 'the application works not in debug mode!'

    """
    if 'app' not in request.fixturenames:
        return
  app = request.getfuncargvalue('app')

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109:


tests\conftest.py:14: in app
app.config[‘SECRET_KEY’] = config[‘TEST’][‘SECRET_KEY’]


self = <configparser.ConfigParser object at 0x0000000004FE3E10>, key = ‘TEST’

def __getitem__(self, key):
    if key != self.default_section and not self.has_section(key):
      raise KeyError(key)

E KeyError: ‘TEST’

C:\ProgramData\Anaconda3\lib\configparser.py:958: KeyError
_____________________ ERROR at setup of test_basic_movies _____________________

request = <SubRequest ‘_configure_application’ for <Function ‘test_basic_movies’>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x00000000053B74E0>

@pytest.fixture(autouse=True)
def _configure_application(request, monkeypatch):
    """Use `pytest.mark.options` decorator to pass options to your application
    factory::

        @pytest.mark.options(debug=False)
        def test_something(app):
            assert not app.debug, 'the application works not in debug mode!'

    """
    if 'app' not in request.fixturenames:
        return
  app = request.getfuncargvalue('app')

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109:


tests\conftest.py:14: in app
app.config[‘SECRET_KEY’] = config[‘TEST’][‘SECRET_KEY’]


self = <configparser.ConfigParser object at 0x0000000004FE3E10>, key = ‘TEST’

def __getitem__(self, key):
    if key != self.default_section and not self.has_section(key):
      raise KeyError(key)

E KeyError: ‘TEST’

C:\ProgramData\Anaconda3\lib\configparser.py:958: KeyError
__________________ ERROR at setup of test_search_by_movie_id __________________

request = <SubRequest ‘_configure_application’ for <Function ‘test_search_by_movie_id’>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x0000000005325E10>

@pytest.fixture(autouse=True)
def _configure_application(request, monkeypatch):
    """Use `pytest.mark.options` decorator to pass options to your application
    factory::

        @pytest.mark.options(debug=False)
        def test_something(app):
            assert not app.debug, 'the application works not in debug mode!'

    """
    if 'app' not in request.fixturenames:
        return
  app = request.getfuncargvalue('app')

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109:


tests\conftest.py:14: in app
app.config[‘SECRET_KEY’] = config[‘TEST’][‘SECRET_KEY’]


self = <configparser.ConfigParser object at 0x0000000004FE3E10>, key = ‘TEST’

def __getitem__(self, key):
    if key != self.default_section and not self.has_section(key):
      raise KeyError(key)

E KeyError: ‘TEST’

C:\ProgramData\Anaconda3\lib\configparser.py:958: KeyError
__________________ ERROR at setup of test_simple_text_search __________________

request = <SubRequest ‘_configure_application’ for <Function ‘test_simple_text_search’>>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x0000000005358E48>

@pytest.fixture(autouse=True)
def _configure_application(request, monkeypatch):
    """Use `pytest.mark.options` decorator to pass options to your application
    factory::

        @pytest.mark.options(debug=False)
        def test_something(app):
            assert not app.debug, 'the application works not in debug mode!'

    """
    if 'app' not in request.fixturenames:
        return
  app = request.getfuncargvalue('app')

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109:


tests\conftest.py:14: in app
app.config[‘SECRET_KEY’] = config[‘TEST’][‘SECRET_KEY’]


self = <configparser.ConfigParser object at 0x0000000004FE3E10>, key = ‘TEST’

def __getitem__(self, key):
    if key != self.default_section and not self.has_section(key):
      raise KeyError(key)

E KeyError: ‘TEST’

C:\ProgramData\Anaconda3\lib\configparser.py:958: KeyError
============================== warnings summary ===============================
C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

C:\ProgramData\Anaconda3\lib\site-packages\pytest_flask\plugin.py:109: DeprecationWarning: getfuncargvalue is deprecated, use getfixturevalue
app = request.getfuncargvalue(‘app’)

– Docs: https://docs.pytest.org/en/latest/warnings.html
============= 39 deselected, 4 warnings, 4 error in 1.44 seconds ==============

When Application is executed, output log is pasted here

…input Code…
(mflix) D:\SANJAI\university\m220\mflix-python>python run.py

…Output Log…

Traceback (most recent call last):
File “run.py”, line 13, in
app.config[‘MFLIX_DB_URI’] = config[‘PROD’][‘MFLIX_DB_URI’]
File “C:\ProgramData\Anaconda3\lib\configparser.py”, line 958, in getitem
raise KeyError(key)
KeyError: ‘PROD’

I have already updated methods of db.py for ‘Ticket: Connection Pooling’ , ‘Connection: Timeout’ and ‘Connection: Projection’ now.

When I am running application for connection testing, I am getting error which is already pasted in output log.

Why is this error is raised during application execution?

contents of dotini_win.ini file are pasted here

Ticket: Connection

Rename this file to .ini after filling in your MFLIX_DB_URI and your SECRET_KEY

Do not surround the URI with quotes

[PROD]
SECRET_KEY = Nakshatra
MFLIX_DB_URI = mongodb+srv://m220student:password@mflix-bagew.mongodb.net/test

[TEST]
SECRET_KEY = Sangeeta
MFLIX_DB_URI = mongodb+srv://m220student:password@mflix-bagew.mongodb.net/test

I am able to connect my Atlas cluster through SRV string.

Can you please help where I am doing wrong?

Hi Team

I believe this error is due to plugin named “pytest_flask” which is outdated.

Run this to update it in your environment or global if you don’t use any virtual env.

pip install pytest_flask --upgrade

1 Like

I have updated pytest_flask.

Still getting the same problem.

I am running into the same issue.
Any solutions?

My problem is resolved after renaming dotini_win to .ini

Thanks @cevor, running the pytest_flask update solved my problem.

So far I’m finding the documentation and files provided for this class very poor. Spending most of my time searching through these messages to find solutions…shouldn’t be this way.

3 Likes

Yup, that’s literally in the instructions for the class setup :slight_smile:

What is necessary to indicate as SECRET_KEY ??? I am using Windows 10.

In my case, I get these lines of error:

(mflix) c:\mongodb\m220p\mflix-python>pytest -m connection
ImportError while loading conftest 'c:\mongodb\m220p\mflix-python\tests\conftest.py'.
c:\python27\lib\site-packages\six.py:709: in exec_
    exec("""exec _code_ in _globs_, _locs_""")
tests\conftest.py:2: in <module>
    from mflix.factory import create_app
mflix\factory.py:12: in <module>
    from mflix.api.movies import movies_api_v1
E     File "c:\mongodb\m220p\mflix-python\mflix\api\movies.py", line 225
E       **user_info
E        ^
E   SyntaxError: invalid syntax

Could you please share an example of .ini file?? :S

Thanks in advance!!!

Hi,

This is how mine looks and I am able to work through the Tickets,

Ticket: Connection

Rename this file to .ini after filling in your MFLIX_DB_URI and your SECRET_KEY

Do not surround the URI with quotes

[PROD]
SECRET_KEY = super_secret_key_you_should_change
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix-j9tgj.mongodb.net/test

[TEST]
SECRET_KEY = super_secret_testing_key
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix-j9tgj.mongodb.net/test

Also, Which version of Python are you using?

Thanks,
Shahul

2 Likes

I had an error with my Python and Anaconda versions. Now it has been solved with the latest version (Python 3) and running the web correctly. Thank you!

Glad you were able to solve it! Yes, I too thought you need to use the latest version of Python.

Im facing issues running the pytest command. i keep getting the below error. I have upgraded all the dependencies, have Python 3.7 not sure what is missing here.

Also im able to run the run.py script but keep getting an error on the UI stating Currently vlaidating. Not able to get the validation code to move forward. Any help is appreciated. The .ini file is well updated. and also removed the unix and win ini files.

$ pytest -m connection
============================= test session starts =============================
platform win32 – Python 3.7.1, pytest-4.1.1, py-1.7.0, pluggy-0.8.1
rootdir: C:\Users\Ashish\Downloads\mflix-python, inifile:
plugins: flask-0.14.0
collected 43 items / 39 deselected

tests\test_db_connection.py FFFF [100%]

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

hostname = ‘mflix-08o6d.mongod.net

def _get_dns_srv_hosts(hostname):
    try:
      results = resolver.query('_mongodb._tcp.' + hostname, 'SRV')

c:\python37\lib\site-packages\pymongo\uri_parser.py:287:


qname = ‘_mongodb._tcp.mflix-08o6d.mongod.net’, rdtype = ‘SRV’, rdclass = 1
tcp = False, source = None, raise_on_no_answer = True, source_port = 0
lifetime = None

def query(qname, rdtype=dns.rdatatype.A, rdclass=dns.rdataclass.IN,
          tcp=False, source=None, raise_on_no_answer=True,
          source_port=0, lifetime=None):
    """Query nameservers to find the answer to the question.

    This is a convenience function that uses the default resolver
    object to make the query.

    See ``dns.resolver.Resolver.query`` for more information on the
    parameters.
    """

    return get_default_resolver().query(qname, rdtype, rdclass, tcp, source,
                                        raise_on_no_answer, source_port,
                                      lifetime)

…\AppData\Roaming\Python\Python37\site-packages\dns\resolver.py:1102:


self = <dns.resolver.Resolver object at 0x00000169C3FABAC8>
qname = , rdtype = 33
rdclass = 1, tcp = False, source = None, raise_on_no_answer = True
source_port = 0, lifetime = None

def query(self, qname, rdtype=dns.rdatatype.A, rdclass=dns.rdataclass.IN,
          tcp=False, source=None, raise_on_no_answer=True, source_port=0,
          lifetime=None):
    """Query nameservers to find the answer to the question.

    The *qname*, *rdtype*, and *rdclass* parameters may be objects
    of the appropriate type, or strings that can be converted into objects
    of the appropriate type.

    *qname*, a ``dns.name.Name`` or ``text``, the query name.

    *rdtype*, an ``int`` or ``text``,  the query type.

    *rdclass*, an ``int`` or ``text``,  the query class.

    *tcp*, a ``bool``.  If ``True``, use TCP to make the query.

    *source*, a ``text`` or ``None``.  If not ``None``, bind to this IP
    address when making queries.

    *raise_on_no_answer*, a ``bool``.  If ``True``, raise
    ``dns.resolver.NoAnswer`` if there's no answer to the question.

    *source_port*, an ``int``, the port from which to send the message.

    *lifetime*, a ``float``, how long query should run before timing out.

    Raises ``dns.exception.Timeout`` if no answers could be found
    in the specified lifetime.

    Raises ``dns.resolver.NXDOMAIN`` if the query name does not exist.

    Raises ``dns.resolver.YXDOMAIN`` if the query name is too long after
    DNAME substitution.

    Raises ``dns.resolver.NoAnswer`` if *raise_on_no_answer* is
    ``True`` and the query name exists but has no RRset of the
    desired type and class.

    Raises ``dns.resolver.NoNameservers`` if no non-broken
    nameservers are available to answer the question.

    Returns a ``dns.resolver.Answer`` instance.
    """

    if isinstance(qname, string_types):
        qname = dns.name.from_text(qname, None)
    if isinstance(rdtype, string_types):
        rdtype = dns.rdatatype.from_text(rdtype)
    if dns.rdatatype.is_metatype(rdtype):
        raise NoMetaqueries
    if isinstance(rdclass, string_types):
        rdclass = dns.rdataclass.from_text(rdclass)
    if dns.rdataclass.is_metaclass(rdclass):
        raise NoMetaqueries
    qnames_to_try = []
    if qname.is_absolute():
        qnames_to_try.append(qname)
    else:
        if len(qname) > 1:
            qnames_to_try.append(qname.concatenate(dns.name.root))
        if self.search:
            for suffix in self.search:
                qnames_to_try.append(qname.concatenate(suffix))
        else:
            qnames_to_try.append(qname.concatenate(self.domain))
    all_nxdomain = True
    nxdomain_responses = {}
    start = time.time()
    _qname = None # make pylint happy
    for _qname in qnames_to_try:
        if self.cache:
            answer = self.cache.get((_qname, rdtype, rdclass))
            if answer is not None:
                if answer.rrset is None and raise_on_no_answer:
                    raise NoAnswer(response=answer.response)
                else:
                    return answer
        request = dns.message.make_query(_qname, rdtype, rdclass)
        if self.keyname is not None:
            request.use_tsig(self.keyring, self.keyname,
                             algorithm=self.keyalgorithm)
        request.use_edns(self.edns, self.ednsflags, self.payload)
        if self.flags is not None:
            request.flags = self.flags
        response = None
        #
        # make a copy of the servers list so we can alter it later.
        #
        nameservers = self.nameservers[:]
        errors = []
        if self.rotate:
            random.shuffle(nameservers)
        backoff = 0.10
        while response is None:
            if len(nameservers) == 0:
                raise NoNameservers(request=request, errors=errors)
            for nameserver in nameservers[:]:
                timeout = self._compute_timeout(start, lifetime)
                port = self.nameserver_ports.get(nameserver, self.port)
                try:
                    tcp_attempt = tcp
                    if tcp:
                        response = dns.query.tcp(request, nameserver,
                                                 timeout, port,
                                                 source=source,
                                                 source_port=source_port)
                    else:
                        response = dns.query.udp(request, nameserver,
                                                 timeout, port,
                                                 source=source,
                                                 source_port=source_port)
                        if response.flags & dns.flags.TC:
                            # Response truncated; retry with TCP.
                            tcp_attempt = True
                            timeout = self._compute_timeout(start, lifetime)
                            response = \
                                dns.query.tcp(request, nameserver,
                                              timeout, port,
                                              source=source,
                                              source_port=source_port)
                except (socket.error, dns.exception.Timeout) as ex:
                    #
                    # Communication failure or timeout.  Go to the
                    # next server
                    #
                    errors.append((nameserver, tcp_attempt, port, ex,
                                   response))
                    response = None
                    continue
                except dns.query.UnexpectedSource as ex:
                    #
                    # Who knows?  Keep going.
                    #
                    errors.append((nameserver, tcp_attempt, port, ex,
                                   response))
                    response = None
                    continue
                except dns.exception.FormError as ex:
                    #
                    # We don't understand what this server is
                    # saying.  Take it out of the mix and
                    # continue.
                    #
                    nameservers.remove(nameserver)
                    errors.append((nameserver, tcp_attempt, port, ex,
                                   response))
                    response = None
                    continue
                except EOFError as ex:
                    #
                    # We're using TCP and they hung up on us.
                    # Probably they don't support TCP (though
                    # they're supposed to!).  Take it out of the
                    # mix and continue.
                    #
                    nameservers.remove(nameserver)
                    errors.append((nameserver, tcp_attempt, port, ex,
                                   response))
                    response = None
                    continue
                rcode = response.rcode()
                if rcode == dns.rcode.YXDOMAIN:
                    ex = YXDOMAIN()
                    errors.append((nameserver, tcp_attempt, port, ex,
                                   response))
                    raise ex
                if rcode == dns.rcode.NOERROR or \
                        rcode == dns.rcode.NXDOMAIN:
                    break
                #
                # We got a response, but we're not happy with the
                # rcode in it.  Remove the server from the mix if
                # the rcode isn't SERVFAIL.
                #
                if rcode != dns.rcode.SERVFAIL or not self.retry_servfail:
                    nameservers.remove(nameserver)
                errors.append((nameserver, tcp_attempt, port,
                               dns.rcode.to_text(rcode), response))
                response = None
            if response is not None:
                break
            #
            # All nameservers failed!
            #
            if len(nameservers) > 0:
                #
                # But we still have servers to try.  Sleep a bit
                # so we don't pound them!
                #
                timeout = self._compute_timeout(start, lifetime)
                sleep_time = min(timeout, backoff)
                backoff *= 2
                time.sleep(sleep_time)
        if response.rcode() == dns.rcode.NXDOMAIN:
            nxdomain_responses[_qname] = response
            continue
        all_nxdomain = False
        break
    if all_nxdomain:
      raise NXDOMAIN(qnames=qnames_to_try, responses=nxdomain_responses)

E dns.resolver.NXDOMAIN: None of DNS query names exist: _mongodb._tcp.mflix-08o6d.mongod.net., _mongodb._tcp.mflix-08o6d.mongod.net.

…\AppData\Roaming\Python\Python37\site-packages\dns\resolver.py:1002: NXDOMAIN

During handling of the above exception, another exception occurred:

client = <FlaskClient <Flask ‘mflix.factory’>>
config = <Config {‘ENV’: ‘production’, ‘DEBUG’: False, ‘TESTING’: False, ‘PROPAGATE_EXCEPTIONS’: True, 'PRESERVE_CONTEXT_ON_EXC…d_claims at 0x00000169C3F68730>, ‘MFLIX_DB_URI’: ‘mongodb+srv://m220student:m220password@mflix-08o6d.mongod.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”]
c:\python37\lib\site-packages\pymongo\mongo_client.py:494: in init
res = uri_parser.parse_uri(entity, port, warn=True)
c:\python37\lib\site-packages\pymongo\uri_parser.py:399: in parse_uri
nodes = _get_dns_srv_hosts(fqdn)


hostname = ‘mflix-08o6d.mongod.net

def _get_dns_srv_hosts(hostname):
    try:
        results = resolver.query('_mongodb._tcp.' + hostname, 'SRV')
    except Exception as exc:
      raise ConfigurationError(str(exc))

E pymongo.errors.ConfigurationError: None of DNS query names exist: _mongodb._tcp.mflix-08o6d.mongod.net., _mongodb._tcp.mflix-08o6d.mongod.net.

c:\python37\lib\site-packages\pymongo\uri_parser.py:289: ConfigurationError
______________________________ test_basic_movies ______________________________

hostname = ‘mflix-08o6d.mongod.net

def _get_dns_srv_hosts(hostname):
    try:
      results = resolver.query('_mongodb._tcp.' + hostname, 'SRV')

c:\python37\lib\site-packages\pymongo\uri_parser.py:287:


qname = ‘_mongodb._tcp.mflix-08o6d.mongod.net’, rdtype = ‘SRV’, rdclass = 1
tcp = False, source = None, raise_on_no_answer = True, source_port = 0
lifetime = None

def query(qname, rdtype=dns.rdatatype.A, rdclass=dns.rdataclass.IN,
          tcp=False, source=None, raise_on_no_answer=True,
          source_port=0, lifetime=None):
    """Query nameservers to find the answer to the question.

    This is a convenience function that uses the default resolver
    object to make the query.

    See ``dns.resolver.Resolver.query`` for more information on the
    parameters.
    """

    return get_default_resolver().query(qname, rdtype, rdclass, tcp, source,
                                        raise_on_no_answer, source_port,
                                      lifetime)

…\AppData\Roaming\Python\Python37\site-packages\dns\resolver.py:1102:


Your URI looks wrong.

Please post content of your .ini file. Without looking at it, it is difficult to come to a conclusion

[PROD]
SECRET_KEY = Ashish_Prod
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix-08o6d.mongodb.net/

[TEST]
SECRET_KEY = Ashish_Test
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix-08o6d.mongodb.net/

For some reason upgrading the Flask module made the application work although the pytests still dont work. Maybe something to do with the older versions of pytest modules. Tried upgrading but that too dint work.

For im able to move forward as im able to get the validation codes.

Thanks again for chiming in.

1 Like

At this point most of the tests from the status page should still fail as they are tests for future homeworks. As long as you get your validation codes for the current labs you are good to go.

thank you cevor … it helped me to resolve issues in KeyError(key)