pymongo.errors.ConfigurationError: A DNS label is empty

I’m getting this error when I try to connect to Atlas Mongo


Here is my code:

import pymongo
from pymongo import MongoClient
import dns

cluster = MongoClient(f"mongodb+srv://myusername:password@cucumber.iq05j.mongodb.net/datebase?retryWrites=true&w=majority"

And here is full TraceBack:

  Traceback (most recent call last):
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\pymongo\srv_resolver.py", line 72, in _resolve_uri
    results = resolver.query('_mongodb._tcp.' + self.__fqdn, 'SRV',
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\resolver.py", line 1100, in query
    return get_default_resolver().query(qname, rdtype, rdclass, tcp, source,
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\resolver.py", line 1073, in get_default_resolver
    reset_default_resolver()
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\resolver.py", line 1085, in reset_default_resolver
    default_resolver = Resolver()
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\resolver.py", line 543, in __init__
    self.read_registry()
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\resolver.py", line 720, in read_registry
    self._config_win32_fromkey(key, False)
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\resolver.py", line 674, in _config_win32_fromkey
    self._config_win32_domain(dom)
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\resolver.py", line 639, in _config_win32_domain
    self.domain = dns.name.from_text(str(domain))
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\name.py", line 889, in from_text
    return from_unicode(text, origin, idna_codec)
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\name.py", line 852, in from_unicode
    raise EmptyLabel
dns.name.EmptyLabel: A DNS label is empty.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\invar\PycharmProjects\DiscordBot\main.py", line 15, in <module>
    cluster = MongoClient(f"mongodb+srv://RamboDash:mxls0771@helpy.iq05j.mongodb.net/Bot?retryWrites=true&w=majority")
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\pymongo\mongo_client.py", line 639, in __init__
    res = uri_parser.parse_uri(
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\pymongo\uri_parser.py", line 500, in parse_uri
    nodes = dns_resolver.get_hosts()
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\pymongo\srv_resolver.py", line 102, in get_hosts
    _, nodes = self._get_srv_response_and_hosts(True)
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\pymongo\srv_resolver.py", line 83, in _get_srv_response_and_hosts
    results = self._resolve_uri(encapsulate_errors)
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\pymongo\srv_resolver.py", line 79, in _resolve_uri
    raise ConfigurationError(str(exc))
pymongo.errors.ConfigurationError: A DNS label is empty.

Process finished with exit code 1

Regards,

The name cucumber.iq05j.mongodb.net does not appear to be a valid active Atlas cluster name.

May be you have a typo. Could you share the cluster status window snapshot?

cucumber was just a place holder.
The real cluster name is Helpy

It is really hard to help debug and a waste of time when you are given false information, placeholder or not.

The DNS information for Helpy is correct:

;; ANSWER SECTION:
Helpy.iq05j.mongodb.net. 59	IN	TXT	"authSource=admin&replicaSet=atlas-leemhu-shard-0"

;; ANSWER SECTION:
_mongodb._tcp.Helpy.iq05j.mongodb.net. 59 IN SRV 0 0 27017 helpy-shard-00-00.iq05j.mongodb.net.
_mongodb._tcp.Helpy.iq05j.mongodb.net. 59 IN SRV 0 0 27017 helpy-shard-00-01.iq05j.mongodb.net.
_mongodb._tcp.Helpy.iq05j.mongodb.net. 59 IN SRV 0 0 27017 helpy-shard-00-02.iq05j.mongodb.net.

Since now that we now that the DNS information is correct, we can suggest other things to check.

You either missing some package, or you internet or VPN provider does not support SRV queries. Try connecting with the old style non-SRV URI.

Thanks!!
I’ve just put a non-SRV link and now it is perfectly working!
Thanks a lot!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.