3

hello i'm trying a "python manage.py runserver" command in the cmd
but it returned me this eroor:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5 in position 2: invalid start byte"

on the position

"socket.py", line 791, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)

Here ist the original code in the editor:

def getfqdn(name=''):
     name = name.strip()
    if not name or name == '0.0.0.0':
        name = gethostname()
    try:
        hostname, aliases, ipaddrs = gethostbyaddr(name)
    except error:
        pass
    else:
        aliases.insert(0, hostname)
        for name in aliases:
            if '.' in name:
                break
        else:
            name = hostname
    return name

I have no idea how i can bypass this error since i am not sure if i understand the code.
(first time asking question, thanks for your help!)

2
  • This is a bug in Python; bugs.python.org/issue26227 Commented Mar 18, 2021 at 10:48
  • 1
    thanks @BiOS! that was really just a username problem, now the program works! Commented Mar 19, 2021 at 1:24

1 Answer 1

1

It looks like name contains invalid characters the time it is given as argument to gethostbyaddr() in the socket module.

This is likely because your hostname actually does contains special characers. You may check for this by opening the Terminal or the Command Prompt and type in hostname

If you get something like this as a result:

računalo-codax 

(The above is Croatian for "Codax-computer")

Then you need to change your computer name to make sure it does not contain any special characters like that č. Only plain letters a-zA-Z and numbers 0-9, or a dash -.

Sign up to request clarification or add additional context in comments.

4 Comments

That's dubious advice. Perhaps a better solution is to make sure you only use UTF-8 in your computer names because it's portable between platforms and increasingly becoming the de facto standard for Unicode on the Internet. In the meantime, if you know the encoding that your network administrator used when they named the computer, tell your library to decode('windows-1250') instead (assuming that's the actual encoding you want to decode).
You might call it dubious advice but it was litterally how I had solved it myself.
Oh I'm sure it works but yielding to the imperialist pressure is an unattractive workaround. We should be able to use any characters we choose in our private computer names.
thanks for your help, i have solved the problem! It was just because of the username...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.