Watching for file changes with StatReloader
Performing system checks... System check identified no issues (0 silenced).
Exception in thread django-main-thread:
Traceback (most recent call last):
File "D:\Anaconda3\lib\threading.py", line 980, in _bootstrap_inner
self.run()
File "D:\Anaconda3\lib\threading.py", line 917, in run
self._target(*self._args, **self._kwargs)
File "D:\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "D:\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 120, in inner_run
self.check_migrations()
File "D:\Anaconda3\lib\site-packages\django\core\management\base.py", line 453, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "D:\Anaconda3\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "D:\Anaconda3\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
self.build_graph()
File "D:\Anaconda3\lib\site-packages\django\db\migrations\loader.py", line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "D:\Anaconda3\lib\site-packages\django\db\migrations\recorder.py", line 73, in applied_migrations
if self.has_table():
File "D:\Anaconda3\lib\site-packages\django\db\migrations\recorder.py", line 56, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "D:\Anaconda3\lib\site-packages\django\db\backends\base\base.py", line 256, in cursor
return self._cursor()
File "D:\Anaconda3\lib\site-packages\django\db\backends\base\base.py", line 233, in _cursor
self.ensure_connection()
File "D:\Anaconda3\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
self.connect()
File "D:\Anaconda3\lib\site-packages\django\db\backends\base\base.py", line 197, in connect
self.init_connection_state()
File "D:\Anaconda3\lib\site-packages\django\db\backends\mysql\base.py", line 231, in init_connection_state
if self.features.is_sql_auto_is_null_enabled:
File "D:\Anaconda3\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "D:\Anaconda3\lib\site-packages\django\db\backends\mysql\features.py", line 82, in is_sql_auto_is_null_enabled
cursor.execute('SELECT @@SQL_AUTO_IS_NULL')
File "D:\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 103, in execute
sql = self.db.ops.last_executed_query(self.cursor, sql, params)
File "D:\Anaconda3\lib\site-packages\django\db\backends\mysql\operations.py", line 146, in last_executed_query
query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode'
D:\Anaconda3\Lib\site-packages\django\db\backends\mysql\operations.py changed, reloading.
Performing system checks... Watching for file changes with StatReloader
System check identified no issues (0 silenced).
Exception in thread django-main-thread:
Traceback (most recent call last):
File "D:\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 82, in _execute
return self.cursor.execute(sql)
File "D:\Anaconda3\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute
return self.cursor.execute(query, args)
File "D:\Anaconda3\lib\site-packages\pymysql\cursors.py", line 148, in execute
result = self._query(query)
File "D:\Anaconda3\lib\site-packages\pymysql\cursors.py", line 310, in _query
conn.query(q)
File "D:\Anaconda3\lib\site-packages\pymysql\connections.py", line 548, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "D:\Anaconda3\lib\site-packages\pymysql\connections.py", line 775, in _read_query_result
result.read()
File "D:\Anaconda3\lib\site-packages\pymysql\connections.py", line 1156, in read
first_packet = self.connection._read_packet()
File "D:\Anaconda3\lib\site-packages\pymysql\connections.py", line 725, in _read_packet
packet.raise_for_error()
File "D:\Anaconda3\lib\site-packages\pymysql\protocol.py", line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File "D:\Anaconda3\lib\site-packages\pymysql\err.py", line 143, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1046, 'No database selected') The above exception was the direct cause of the following exception: Traceback (most recent call last):
File "D:\Anaconda3\lib\threading.py", line 980, in _bootstrap_inner
self.run()
File "D:\Anaconda3\lib\threading.py", line 917, in run
self._target(*self._args, **self._kwargs)
File "D:\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "D:\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 120, in inner_run
self.check_migrations()
File "D:\Anaconda3\lib\site-packages\django\core\management\base.py", line 453, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "D:\Anaconda3\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "D:\Anaconda3\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
self.build_graph()
File "D:\Anaconda3\lib\site-packages\django\db\migrations\loader.py", line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "D:\Anaconda3\lib\site-packages\django\db\migrations\recorder.py", line 73, in applied_migrations
if self.has_table():
File "D:\Anaconda3\lib\site-packages\django\db\migrations\recorder.py", line 56, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "D:\Anaconda3\lib\site-packages\django\db\backends\base\introspection.py", line 48, in table_names
return get_names(cursor)
File "D:\Anaconda3\lib\site-packages\django\db\backends\base\introspection.py", line 43, in get_names
return sorted(ti.name for ti in self.get_table_list(cursor)
File "D:\Anaconda3\lib\site-packages\django\db\backends\mysql\introspection.py", line 55, in get_table_list
cursor.execute("SHOW FULL TABLES")
File "D:\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 99, in execute
return super().execute(sql, params)
File "D:\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "D:\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "D:\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "D:\Anaconda3\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "D:\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 82, in _execute
return self.cursor.execute(sql)
File "D:\Anaconda3\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute
return self.cursor.execute(query, args)
File "D:\Anaconda3\lib\site-packages\pymysql\cursors.py", line 148, in execute
result = self._query(query)
File "D:\Anaconda3\lib\site-packages\pymysql\cursors.py", line 310, in _query
conn.query(q)
File "D:\Anaconda3\lib\site-packages\pymysql\connections.py", line 548, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "D:\Anaconda3\lib\site-packages\pymysql\connections.py", line 775, in _read_query_result
result.read()
File "D:\Anaconda3\lib\site-packages\pymysql\connections.py", line 1156, in read
first_packet = self.connection._read_packet()
File "D:\Anaconda3\lib\site-packages\pymysql\connections.py", line 725, in _read_packet
packet.raise_for_error()
File "D:\Anaconda3\lib\site-packages\pymysql\protocol.py", line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File "D:\Anaconda3\lib\site-packages\pymysql\err.py", line 143, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.OperationalError: (1046, 'No database selected')

Django启动时报错

问题原因:

  • 从 Error信息中可以得知,这是 str编码的问题,而且还是和 mysql进行交互之间的编码问题。

  • python3里面,字符串要先encode手动指定其为某一编码的字节码之后,才能decode解码。

SO:

  点击最后一条异常信息的地址,将query = query.decode(errors='replace') 修改成 query = query.encode(errors='replace')

Django项目启动 AttributeError: ‘str‘ object has no attribute ‘decode‘ 问题的更多相关文章

  1. Django项目与mysql交互进行数据迁移时报错:AttributeError: 'str' object has no attribute 'decode'

    问题描述 Django项目启动,当我们执行命令 python manage.py makemigrations 出现如下错误: File , in last_executed_query query ...

  2. Django2.2报错 AttributeError: 'str' object has no attribute 'decode'

    准备将 Django 连接到 MySQL,在命令行输入命令 python manage.py makemigrations 后报错: AttributeError: 'str' object has ...

  3. python3.x运行的坑:AttributeError: 'str' object has no attribute 'decode'

    1.Python3.x和Python2.X版本有一些区别,我遇到了两个问题如下: a.第一个报:mysqlclient 1.3版本不对: 解决办法:注释掉这行即可: b.第二个报:字符集的问题: 报错 ...

  4. 解决编码问题:AttributeError: 'str' object has no attribute 'decode'

    1. 问题发现: 出现:读取文件,对其进行解码,出现错误,AttributeError: 'str' object has no attribute 'decode' 解释:属性错误,str对象不包含 ...

  5. AttributeError: 'str' object has no attribute 'decode'

    ue = e.decode('latin-1')修改为: ue = e.encode('ascii', 'strict')

  6. 执行: python manage.py makemigrations报AttributeError: 'str' object has no attribute 'decode'

    找到错误代码(line146):query = query.encode(errors='replace') 解决方法:把decode改为encode即可.

  7. Django 运行报异常:AttributeError: 'str' object has no attribute 'get'

    Technorati Tags: Python,Django,Web 在使用django.contrib.auth用户机制进行用户的验证.登录.注销操作时,遇到这个异常. 首先是写了一个登录的视图,要 ...

  8. Python PyInstaller 打包报错:AttributeError: 'str' object has no attribute 'items'

    pyinstaller打包时报错:AttributeError: 'str' object has no attribute 'items' 网上查询,可能是setuptools比较老: 更新一下 p ...

  9. 【Python-遇到的Error】AttributeError: 'str' object has no attribute 'input_text'

    学习类的实例化的时候遇到了AttributeError: 'str' object has no attribute 'input_text', 以下是报错的代码及修改正确的代码. class shu ...

随机推荐

  1. 记一次 .NET 某电子病历 CPU 爆高分析

    一:背景 1.讲故事 前段时间有位朋友微信找到我,说他的程序出现了 CPU 爆高,帮忙看下程序到底出了什么情况?图就不上了,我们直接进入主题. 二:WinDbg 分析 1. CPU 真的爆高吗? 要确 ...

  2. vite vue3 规范化与Git Hooks

    在 <JS 模块化>系列开篇中,曾提到前端技术的发展不断融入很多后端思想,形成前端的"四个现代化":工程化.模块化.规范化.流程化.在该系列文章中已详细介绍了模块化的发 ...

  3. 在某网站的登录页面登录时如果选择“记住用户名”,登录成功后会跳转到一个中间层(页面代码将登录的用户名和密码存在cookie),中间页面中存在一个超链接,单击超链接可以链接到第三个页面查看信息。若选择“

    Response实现登录并记录用户名和密码信息 在某网站的登录页面登录时如果选择"记住用户名",登录成功后会跳转到一个中间层(页面代码将登录的用户名和密码存在cookie),中间页 ...

  4. 一天五道Java面试题----第八天(怎么处理慢查询--------->简述Myisam和innodb的区别)

    这里是参考B站上的大佬做的面试题笔记.大家也可以去看视频讲解!!! 文章目录 1.怎么处理慢查询 2.ACID靠什么保证的 3.什么是MVCC 4.mysql主从同步原理 5.简述Myisam和inn ...

  5. 2022年最新最详细IDEA关联数据库方式、在IDEA中进行数据库的可视化操作(包含图解过程)

    文章目录 1.使用IDEA关联Mysql数据库的详细操作步骤 1.1 打开侧边栏的Database 2.2. 选择要连接的数据库(Mysql) 2.3 .输入要连接的数据库.用户名.密码 2.4 .点 ...

  6. Spring中过滤器(Filter)和拦截器(Interceptor)的区别和联系

    在我们日常的开发中,我们经常会用到Filter和Interceptor.有时同一个功能.Filter可以做,Interceptor也可以做.有时就需要考虑使用哪一个比较好.这篇文章主要介绍一下,二者的 ...

  7. C# RulesEngine 规则引擎:从入门到看懵

    说明 RulesEngine 是 C# 写的一个规则引擎类库,读者可以从这些地方了解它: 仓库地址: https://github.com/microsoft/RulesEngine 使用方法: ht ...

  8. 二、Celery执行一步任务

    二.Celery执行异步任务 2.1.基本使用 创建项目celerypro 创建异步任务执行文件celery_task: import celery import time backend='redi ...

  9. Linux--多线程(二)

    线程的同步和互斥 基本概念 概述:现在操作系统基本都是多任务的操作系统,同时有大量可以调度的实体在运行.在多任务操作系统当中,同时运行的多个任务可能: 都需要访问/使用同一种资源 多个任务之间有依赖关 ...

  10. 词云(WordCloud)

    WordCloud的参数: font_path:可用于指定字体路径 width:词云的宽度,默认为 400: height:词云的⾼度,默认为 200: mask:蒙版,可⽤于定制词云的形状: min ...