# Encoding with 'idna' codec failed (UnicodeError: label empty or too long)

**URL:** <https://forum.djangoproject.com/t/encoding-with-idna-codec-failed-unicodeerror-label-empty-or-too-long/20568>\
**Category:** Forms & APIs\
**Created:** [April 27, 2023, 12:09pm UTC](https://forum.djangoproject.com/t/encoding-with-idna-codec-failed-unicodeerror-label-empty-or-too-long/20568 "2023-04-27T12:09:13Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 28, 2023, 2:46am UTC](https://forum.djangoproject.com/t/encoding-with-idna-codec-failed-unicodeerror-label-empty-or-too-long/20568/21 "2023-04-28T02:46:46Z")

</div>

I don’t see anything wrong in this file, but these entries for “unchecky” lead me to believe you’ve got some software installed that is interfering with normal DNS resolution.

You can _try_ uncommenting these lines. Traditionally, the hosts file is checked before DNS.

```auto
# 127.0.0.1 localhost
# ::1 localhost

```

If that doesn’t work, I don’t know what else you can do locally.

---

<div class="post-metadata">

**Author:** ![tomislavm021](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tomislavm021/32/13462_2.png) [@tomislavm021](https://forum.djangoproject.com/u/tomislavm021)\
**Post date:** [April 28, 2023, 11:03am UTC](https://forum.djangoproject.com/t/encoding-with-idna-codec-failed-unicodeerror-label-empty-or-too-long/20568/22 "2023-04-28T11:03:43Z")

</div>

Thank you, i did that, but the problem is still present.  
Could you please tell me more about that software, i mean i can search for it and uninstall or change or something, just would like to know what to look for.

And when you say “I don’t know what else you can do locally”, do you mean that this should work when i upload the project online? Like, the error is locally on my pc, and that is causing this issue?

Thank you very much

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 28, 2023, 1:08pm UTC](https://forum.djangoproject.com/t/encoding-with-idna-codec-failed-unicodeerror-label-empty-or-too-long/20568/23 "2023-04-28T13:08:09Z")

</div>

Side question: Is your computer part of a Windows Active Directory domain?

You might also try changing these lines in your hosts file from:

> [@tomislavm021](#):
>
> ```auto
> 127.0.0.1 localhost
> ::1 localhost
> 
> ```

to:

```auto
127.0.0.1 localhost localhost.localdomain
::1 localhost localhost.localdomain

```

> [@tomislavm021](#):
>
> i mean i can search for it and uninstall or change or something, just would like to know what to look for.

I can’t tell you what to look for, because I don’t have any specific examples.

> [@tomislavm021](#):
>
> Like, the error is locally on my pc, and that is causing this issue?

Yes, this error is local on your PC. Either something is misconfigured on your system (but I don’t know what that might be), or you have some software installed that is interfering with normal DNS resolution.

> [@tomislavm021](#):
>
> this should work when i upload the project online?

That depends. If you’re deploying to something like a linux server, it should work fine - unless it’s also misconfigured in the same way (if that’s the issue here). Or, if you’re going to deploy to another Windows system, if _that_ system also has the same software installed, it may also display the same behavior.

Since I really don’t know what’s going on here, I can only guess.

To be clear, this is **not** a Django issue. The `socket.getfqdn` function is a standard Python library function - you would get this same invalid response from any Python code using it.

---

<div class="post-metadata">

**Author:** ![tomislavm021](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tomislavm021/32/13462_2.png) [@tomislavm021](https://forum.djangoproject.com/u/tomislavm021)\
**Post date:** [April 28, 2023, 1:28pm UTC](https://forum.djangoproject.com/t/encoding-with-idna-codec-failed-unicodeerror-label-empty-or-too-long/20568/24 "2023-04-28T13:28:41Z")

</div>

Thank you for all your help.

This is really frustrating. The laptop is new, i guess no special programs are installed that should cause this error to appear…

Anyhow i typed set user to cms and i saw this info:

set user  
USERDOMAIN=DESKTOP-2OGR8E0  
USERDOMAIN\_ROAMINGPROFILE=DESKTOP-2OGR8E0  
USERNAME=Dell  
USERPROFILE=C:\Users\Dell

Is that what you meant?

Should i try to upload to Vultr or Digital Ocean and test if it works?

I was just following a tutorial. Everything up until now is working, i get no bugs, i mean i do but those are the mistakes i make while creating something, but this is really stopping me from going forward, i don’t know what to do 😕

I am grateful for your time and trying to help!

---

<div class="post-metadata">

**Author:** ![tomislavm021](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tomislavm021/32/13462_2.png) [@tomislavm021](https://forum.djangoproject.com/u/tomislavm021)\
**Post date:** [April 28, 2023, 1:31pm UTC](https://forum.djangoproject.com/t/encoding-with-idna-codec-failed-unicodeerror-label-empty-or-too-long/20568/25 "2023-04-28T13:31:22Z")

</div>

Somewhere i read that the problem may be in that length, if it is longer that 64 characters or something like that, and somebody have mentioned that idna file…it was like a month ago, don’t really remember…

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 28, 2023, 1:53pm UTC](https://forum.djangoproject.com/t/encoding-with-idna-codec-failed-unicodeerror-label-empty-or-too-long/20568/26 "2023-04-28T13:53:17Z")

</div>

The error is being caused by whatever is causing the Python `socket.getfqdn` function to return this value:

> [@tomislavm021](#):
>
> ```auto
> >>> socket.getfqdn()
> >>> 'DESKTOP-2OGR8E0…home'
> 
> ```

Notice how the name being returned has three consecutive periods in it. That makes it an invalid name.

I don’t know what might be causing that function to return that value, I’ve never seen this happen before _except_ when I intentionally set it up that way.

---

<div class="post-metadata">

**Author:** ![tomislavm021](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tomislavm021/32/13462_2.png) [@tomislavm021](https://forum.djangoproject.com/u/tomislavm021)\
**Post date:** [April 28, 2023, 2:08pm UTC](https://forum.djangoproject.com/t/encoding-with-idna-codec-failed-unicodeerror-label-empty-or-too-long/20568/27 "2023-04-28T14:08:11Z")

</div>

Thank you. Okay so my friend did all the setup for windows and whatnot…maybe he entered that ‘DESKTOP-2OGR8E0…home’ name…

Should i reinstall windows with default options or can you please recommend the approach to not have those 3 dots, what should be the output for socket.getfqdn()?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 28, 2023, 2:25pm UTC](https://forum.djangoproject.com/t/encoding-with-idna-codec-failed-unicodeerror-label-empty-or-too-long/20568/28 "2023-04-28T14:25:44Z")

</div>

Normally you only define the host name - the first part of that, which would be `DESKTOP-2OGR8E0`. The domain name (everything after the first period) is _usually_ assigned by your ISP when you connect to the internet. For example, the domain assigned to this laptop I’m using right now is `hsd1.pa.comcast.net`. That means that the output from the `getfqdn` function on _this_ laptop is `ASUS_1.hsd1.pa.comcast.net`.

If your laptop were connected to my network, I would expect to see `DESKTOP-2OGR8E0.hsd1.pa.comcast.net`.

So without knowing more about the network you’re connected to, it’s going to be tough to figure this out - and I don’t even know what to tell you to look at.

Most importantly, there’s a chance that reinstalling windows isn’t going to make any difference at all if it’s your network configuration causing this.

---

<div class="post-metadata">

**Author:** ![tomislavm021](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tomislavm021/32/13462_2.png) [@tomislavm021](https://forum.djangoproject.com/u/tomislavm021)\
**Post date:** [April 28, 2023, 3:23pm UTC](https://forum.djangoproject.com/t/encoding-with-idna-codec-failed-unicodeerror-label-empty-or-too-long/20568/29 "2023-04-28T15:23:17Z")

</div>

Okay…so now i tried to access my phone wifi via hotspot, and everthing seems to be working. Both email verification and password reset. So the problem is in the wifi router.

You helped me a lot, if weren’t for you, i would not have any idea to try to access mobile internet…should i ask the isp provider (have in mind it is the same one, same operator) why does it add those 3 dots and can i remove them?

Anyhow, thank you very much again 🙂

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 28, 2023, 3:48pm UTC](https://forum.djangoproject.com/t/encoding-with-idna-codec-failed-unicodeerror-label-empty-or-too-long/20568/30 "2023-04-28T15:48:23Z")

</div>

It can’t hurt to ask. However, based upon my personal experiences with most residential ISPs, I would have the opinion that it’s unlikely you are going to get an adaquate answer.

[Previous page](https://forum.djangoproject.com/t/encoding-with-idna-codec-failed-unicodeerror-label-empty-or-too-long/20568.md?page=1)
