【问题标题】:Django UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 5: invalid continuation byteDjango UnicodeDecodeError: \'utf-8\' 编解码器无法解码位置 5 中的字节 0xcf:连续字节无效
【发布时间】:2022-12-28 21:26:19
【问题描述】:

我以前没有见过这样的问题。我翻遍了谷歌,没有找到答案。虽然其他人也有类似的问题,但他们的解决方案并不适合我。 (英文路径中的用户名也是如此)

问题: 在第一个 Django 项目manage.py runserver 有错误:

Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you
 apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
August 04, 2022 - 01:06:46
Django version 4.1, using settings 'base.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\pthn\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\pthn\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\pthn\lib\site-packages\django\utils\autoreload.py", line 64, in wrapp
er
    fn(*args, **kwargs)
  File "C:\pthn\lib\site-packages\django\core\management\commands\runserver.py",
 line 158, in inner_run
    run(
  File "C:\pthn\lib\site-packages\django\core\servers\basehttp.py", line 236, in
 run
    httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
  File "C:\pthn\lib\site-packages\django\core\servers\basehttp.py", line 76, in
__init__
    super().__init__(*args, **kwargs)
  File "C:\pthn\lib\socketserver.py", line 452, in __init__
    self.server_bind()
  File "C:\pthn\lib\wsgiref\simple_server.py", line 50, in server_bind
    HTTPServer.server_bind(self)
  File "C:\pthn\lib\http\server.py", line 140, in server_bind
    self.server_name = socket.getfqdn(host)
  File "C:\pthn\lib\socket.py", line 756, in getfqdn
    hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 5: invalid
continuation byte


host folder(C:\Windows\System32\drivers\etc) - 

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost

【问题讨论】:

    标签: python django django-errors


    【解决方案1】:

    在启动服务器之前尝试迁移。

    python manage.py makemigrations
    python manage.py migrate
    

    【讨论】:

    • 没有,没有任何改变(
    • 你把你的申请放在INSTALLED_APPS了吗?
    • 这是 startproject 命令后的默认应用程序,所以它应该显示一个欢迎页面,我不认为这是问题所在
    • 结果一切都离django很远,我以为我把用户名改到了最后,但是我不得不一路走到计算机>属性>更改属性并更改全名,感​​谢您的时间
    【解决方案2】:

    结果一切都离django很远,我以为我把用户名改到了最后,但是我不得不一路走到计算机>属性>更改属性并更改全名,感​​谢您的时间

    【讨论】:

      猜你喜欢
      • 2021-01-02
      • 2018-01-11
      • 2020-11-02
      • 2021-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多