Aws peering error

def MockQuestionEntry(q1):
    connect_string = r'mongodb+srv://****:****@*****.juivm.mongodb.net/admin?retryWrites=true&w=majority'
    my_client = pymongo.MongoClient(connect_string)
    dbname = my_client['SafalHonge']
    collection_name = dbname["Mock"]
    print("Work done")
    try:
        collection_name.insert_many([q1])
    except(DuplicateKeyError, BulkWriteError) as err:
        raise IntegrityError(err)
    count = collection_name.count()
    print(count)

we are using this function to entering data in our mongo DB database

I made an atlas cluster and hosted it on amazon, now I am accessing it through vpc peering with AWS lightsail VPC and I am getting the following error

raceback (most recent call last):
  File "C:\Cpanel\venv\lib\site-packages\pymongo\srv_resolver.py", line 88, in _resolve_uri
    results = _resolve('_mongodb._tcp.' + self.__fqdn, 'SRV',
  File "C:\Cpanel\venv\lib\site-packages\pymongo\srv_resolver.py", line 46, in _resolve
    return resolver.resolve(*args, **kwargs)
  File "C:\Cpanel\venv\lib\site-packages\dns\resolver.py", line 1305, in resolve
    return get_default_resolver().resolve(qname, rdtype, rdclass, tcp, source,
  File "C:\Cpanel\venv\lib\site-packages\dns\resolver.py", line 1163, in resolve
    (request, answer) = resolution.next_request()
  File "C:\Cpanel\venv\lib\site-packages\dns\resolver.py", line 612, in next_request
    raise NXDOMAIN(qnames=self.qnames_to_try,

During handling of the above exception (The DNS query name does not exist: _mongodb._tcp.safalhonge.e.juivm.mongodb.net.), another exception occurred:
  File "C:\Cpanel\venv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Cpanel\venv\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Cpanel\venv\lib\site-packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "C:\Cpanel\SafalHonge\CPanelAuth\views.py", line 155, in Chapter_wise
    MockQuestionEntry(details)
  File "C:\Cpanel\SafalHonge\CPanelAuth\DbConnection.py", line 37, in MockQuestionEntry
    my_client = pymongo.MongoClient(connect_string)
  File "C:\Cpanel\venv\lib\site-packages\pymongo\mongo_client.py", line 670, in __init__
    res = uri_parser.parse_uri(
  File "C:\Cpanel\venv\lib\site-packages\pymongo\uri_parser.py", line 524, in parse_uri
    nodes = dns_resolver.get_hosts()
  File "C:\Cpanel\venv\lib\site-packages\pymongo\srv_resolver.py", line 118, in get_hosts
    _, nodes = self._get_srv_response_and_hosts(True)
  File "C:\Cpanel\venv\lib\site-packages\pymongo\srv_resolver.py", line 99, in _get_srv_response_and_hosts
    results = self._resolve_uri(encapsulate_errors)
  File "C:\Cpanel\venv\lib\site-packages\pymongo\srv_resolver.py", line 95, in _resolve_uri
    raise ConfigurationError(str(exc))

Exception Type: ConfigurationError at /Chapter_wise/
Exception Value: The DNS query name does not exist: _mongodb._tcp.safalhonge.e.juivm.mongodb.net.

Hi @ADITYA_SHARMA2 - Welcome to the community!

Exception Value: The DNS query name does not exist: _mongodb._tcp.safalhonge.e.juivm.mongodb.net

The above error indicates the DNS in use isn’t able to resolve the SRV record contained in the connection string. However, I tried resolving this on my end and wasn’t able to get the expected response.

I made an atlas cluster and hosted it on amazon, now I am accessing it through vpc peering with AWS lightsail VPC and I am getting the following error

Did you attempt accessing the cluster using the same connection string through the public internet rather than connecting through VPC peering? You can do this by adding the public IP of the client(s) to the Access List and attempting connection again.

For additional troubleshooting steps that you may take, try connecting using the standard connection string and advise of any errors which occur.

Best Regards,
Jason

1 Like

hi @Jason_Tran yes when I am running the web framework on my localhost with this connection string it is running properly, but when I am hosting it on the vpc it showing the error.

Hi @ADITYA_SHARMA2,

when I am running the web framework on my localhost with this connection string it is running properly, but when I am hosting it on the vpc it showing the error.

Have you attempted to connect without the use of VPC peering from the VPC where your app is hosted as suggested in my previous comment? Please also try the standard connection string to see if you are able to connect.

Additionally, from the client hosted on your VPC, please try to run some network troubleshooting steps such performing a ping and telnet against one (or all) of the node(s) within the cluster using their hostname(s). Please provide the output of those tests here. You can refer to my comment in this post regarding how to find the hostnames of the nodes within your cluster.

Regards,
Jason

1 Like