Ask coding questions

← Back to all posts
Syntax Error: a DNS label is empty |
DwellerIgor (1)

Hello! I wonder if i can ask questions here. Anyways, im making a leveling system for discord server using pymongo database and im getting a syntax error: a DNS label is empty. I wonder what that means and i wanted to ask how to fix that. Please take a look at my code and answer me. Thank you very much!

P.S. If u need more details you can always ask!

InvisibleOne (3227)

Try putting import dnspython at the top, I'm not sure if that is what the problem is as I can't remember how I solved it (It used to happen to me all the time)
I believe it's something to do with your MongoClient line.
Is there a reason you are putting urllib.parse.quote("[email protected])[email protected] and not just putting that password into the string?

DwellerIgor (1)

yes, there is a reason. I was getting another syntax error , so i asked and people told me to put urlib.parse.quote @InvisibleOne

DwellerIgor (1)

and im getting this error now ModuleNotFoundError: No module named 'dnspython' @InvisibleOne

VulcanWM (2912)

import dns
That always works for me @DwellerIgor

DwellerIgor (1)

i think there is a problem with cluster line. this is full error:

`Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/", line 72, in _resolve_uri
results = resolver.query('_mongodb._tcp.' + self.fqdn, 'SRV',
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/dns/", line 1321, in query
return resolve(qname, rdtype, rdclass, tcp, source,
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/dns/", line 1305, in resolve
return get_default_resolver().resolve(qname, rdtype, rdclass, tcp, source,
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/dns/", line 1159, in resolve
resolution = _Resolution(self, qname, rdtype, rdclass, tcp,
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/dns/", line 523, in
qname =, None)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/dns/", line 942, in from_text
raise EmptyLabel A DNS label is empty.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 6, in <module>
import levelsys
File "/home/runner/THANOS-LEVELSYS/", line 13, in <module>
cluster = MongoClient("mongodb+srv://Myself:" + urllib.parse.quote("[email protected])[email protected]") + "@cluster0.4h226.mongodb.n...")
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/", line 639, in init
res = uri_parser.parse_uri(
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/", line 500, in parse_uri
nodes = dns_resolver.get_hosts()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/", line 102, in get_hosts
, nodes = self._get_srv_response_and_hosts(True)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/", line 83, in _get_srv_response_and_hosts
results = self._resolve_uri(encapsulate_errors)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/", line 79, in _resolve_uri
raise ConfigurationError(str(exc))
pymongo.errors.ConfigurationError: A DNS label is empty.
 `@VulcanWM

InvisibleOne (3227)

Sorry I meant import dns it's if you are pip installing it that you put pip install dnspython so I got mixed up. @DwellerIgor

InvisibleOne (3227)

as for urlib.parse.quote I don't know why people would have told you to use that, I never use it, I just put the password in a string with everything.

One other thing, once you get these error's fixed you should hide your srv URL with replit secrets so nobody uses it to connect to your database


DwellerIgor (1)

i dont quite understand what their answer is. what should i [email protected]

Coder100 (18934)

so, instead of using, use and type that in both the dns and the replit domain. @DwellerIgor