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://"

And here is full TraceBack:

  Traceback (most recent call last):
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\pymongo\", line 72, in _resolve_uri
    results = resolver.query('_mongodb._tcp.' + self.__fqdn, 'SRV',
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\", 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\", line 1073, in get_default_resolver
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\", line 1085, in reset_default_resolver
    default_resolver = Resolver()
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\", line 543, in __init__
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\", line 720, in read_registry
    self._config_win32_fromkey(key, False)
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\", line 674, in _config_win32_fromkey
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\", line 639, in _config_win32_domain
    self.domain =
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\", line 889, in from_text
    return from_unicode(text, origin, idna_codec)
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\dns\", line 852, in from_unicode
    raise 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\", line 15, in <module>
    cluster = MongoClient(f"mongodb+srv://")
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\pymongo\", line 639, in __init__
    res = uri_parser.parse_uri(
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\pymongo\", line 500, in parse_uri
    nodes = dns_resolver.get_hosts()
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\pymongo\", line 102, in get_hosts
    _, nodes = self._get_srv_response_and_hosts(True)
  File "C:\Users\invar\PycharmProjects\DiscordBot\venv\lib\site-packages\pymongo\", 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\", line 79, in _resolve_uri
    raise ConfigurationError(str(exc))
pymongo.errors.ConfigurationError: A DNS label is empty.

Process finished with exit code 1


The name 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: 59	IN	TXT	"authSource=admin&replicaSet=atlas-leemhu-shard-0"

;; ANSWER SECTION: 59 IN SRV 0 0 27017 59 IN SRV 0 0 27017 59 IN SRV 0 0 27017

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.

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.