python&&错误录

我不入地狱,谁入地狱?

参考地址:
https://blog.csdn.net/sjpljr/article/details/102953316/

异常类型归纳

  • AttributeError : 试图访问一个对象没有的属性
  • IOError :输入/输出异常;基本上是无法打开文件
  • ImportError :无法引入模块或包;基本上是路径问题或名称错误
  • IndentationError : 语法错误(的子类);代码没有正确对齐
  • IndexError :下标索引超出序列边界,比如当x只有三个元素,却试图访问x[5]
  • KeyError :试图访问字典不存在的键
  • KeyboardInterrupt : Ctrl+C被按下
  • NameError :使用一个还未被赋予对象的变量
  • SyntaxError :Python代码非法,代码不能编译(个人认为这是语法错误,写错了)
  • TypeError :传入对象类型与要求的不符合
  • UnboundLocalError : 试图访问一个还未被设置的局部变量,基本上是由于另有一个同名的全部变量导致你以为正在访问它
  • ValueError :传入一个调用者不期望的值,即使值的类型是正确的

ModuleNotFoundError

错误1:ModuleNotFoundError: No module named ‘MySQLdb’

#!/usr/bin/env python
#coding:utf-8
#导入连接数据库模块
import MySQLdb
'''
log:
Traceback (most recent call last):
  File "D:\backupAll\eclipseRoot\project001\main\index.py", line 5, in <module>
    import MySQLdb
ModuleNotFoundError: No module named 'MySQLdb'
'''

解决方法
1.如下图所示,使用pip软件安装mysqlClient。
在这里插入图片描述
2.重启eclipse软件。

错误2:ModuleNotFoundError: No module named ‘pymysql’

import pymysql
pymysql.install_as_MySQLdb()
'''
log:
Traceback (most recent call last):
  File "D:\backupAll\eclipseRoot\project001\main\__init__.py", line 1, in <module>
    import pymysql
ModuleNotFoundError: No module named 'pymysql'
'''

解决方法
1.打开eclipse软件》点击"Window"》点击"Preferences",出现下图并按照图中红圈依次点击。
在这里插入图片描述
2.如下图所示,在红圈1中确认当前eclipse软件使用的python版本、安装路径;在红圈2中"Packages"标签内确认"PyMySQL"是否存在,若存在则问题解决,若不存在,进行以下操作。
在这里插入图片描述
3.点击红圈3内"Libraries"标签,并点击"NewFolder"按钮,如下图所示
在这里插入图片描述
4.打开相应版本python的安装路径,找到如下图所示的site-packages文件夹,选择"pymysql"文件夹,之后一路确认即可。
在这里插入图片描述
5.若不存在"pymysql"文件夹,请下载pip软件安装pymysql,安装过程中,请确保python环境变量与eclipse使用的python信息(版本、安装路径)一致,信息一致时安装完成后,在site-packages文件夹下才会出现"pymysql"文件夹。
在这里插入图片描述
6.重启eclipse软件,此时Packages"标签内存在"PyMySQL"包。

错误3:ModuleNotFoundError: No module named ‘paramiko’

错误示例:

#!/usr/bin/env python
#coding:utf-8
#导入模块
#!/usr/bin/env python
#coding:utf-8
#导入模块
import paramiko
#实例化
ssh = paramiko.SSHClient()
#应对第一个远程登录的用户签名(yes or no),该行代码默认填写yes。
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
#远程登录账号,密码
ssh.connect('192.168.1.223',22,'root','yibotong')
#设置需要使用Linux命令并捕捉命令返回结果(输入,输出,错误)
stdin,stdout,stderr = ssh.exec_command('df')
#打印结果
print(stdout.read())
ssh.close();
'''
log:
Traceback (most recent call last):
  File "D:\backupAll\eclipseRoot\20190905LearnThread\sshDemo\sshDemo.py", line 4, in <module>
    import paramiko
ModuleNotFoundError: No module named 'paramiko'
'''

解决方法:
如下图所示,在本机的命令行界面使用pip安装paramiko软件即可

C:\Users\Administrator>pip install paramiko
Collecting paramiko
  Downloading https://files.pythonhosted.org/packages/4b/80/74dace9e48b0ef923633dfb5e48798f58a168e4734bca8ecfaf839ba051a/paramiko-2.6.0-py2.py3-none-any.whl (199kB)
     |████████████████████████████████| 204kB 139kB/s
Collecting pynacl>=1.0.1 (from paramiko)
  Downloading https://files.pythonhosted.org/packages/b5/0f/5f21bd04c8f45685c7b72013fc8efaf0e25baf3b77e62b3b915b5b43a7b6/PyNaCl-1.3.0-cp36-cp36m-win_amd64.whl (188kB)
     |████████████████████████████████| 194kB 82kB/s
Collecting bcrypt>=3.1.3 (from paramiko)
  Downloading https://files.pythonhosted.org/packages/60/74/77573c2ee48a7f9fcd72677c43d7be1958db2c62a27602c511907d4dc058/bcrypt-3.1.7-cp36-cp36m-win_amd64.whl
Collecting cryptography>=2.5 (from paramiko)
  Downloading https://files.pythonhosted.org/packages/31/1f/f158f5e83c934ff71cde6c54ebcac48547ec05c01836054ea721daf9840b/cryptography-2.7-cp36-cp36m-win_amd64.whl (1.5MB)
     |████████████████████████████████| 1.5MB 67kB/s
Collecting six (from pynacl>=1.0.1->paramiko)
  Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting cffi>=1.4.1 (from pynacl>=1.0.1->paramiko)
  Downloading https://files.pythonhosted.org/packages/f1/b5/ca3583cbf7975f53b030be773caeabd4e19bac467714e525eaff447a8ac8/cffi-1.12.3-cp36-cp36m-win_amd64.whl (171kB)
     |████████████████████████████████| 174kB 56kB/s
Collecting asn1crypto>=0.21.0 (from cryptography>=2.5->paramiko)
  Downloading https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl (101kB)
     |████████████████████████████████| 102kB 93kB/s
Collecting pycparser (from cffi>=1.4.1->pynacl>=1.0.1->paramiko)
  Downloading https://files.pythonhosted.org/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz (158kB)
     |████████████████████████████████| 163kB 79kB/s
Installing collected packages: six, pycparser, cffi, pynacl, bcrypt, asn1crypto, cryptography, paramiko
  Running setup.py install for pycparser ... done
Successfully installed asn1crypto-0.24.0 bcrypt-3.1.7 cffi-1.12.3 cryptography-2.7 paramiko-2.6.0 pycparser-2.19 pynacl-1.3.0 six-1.12.0

C:\Users\Administrator>pip list
Package      Version
------------ -------
asn1crypto   0.24.0
bcrypt       3.1.7
cffi         1.12.3
cryptography 2.7
mysqlclient  1.4.4
paramiko     2.6.0
pip          19.2.3
pycparser    2.19
PyMySQL      0.9.3
PyNaCl       1.3.0
setuptools   39.0.1
six          1.12.0

在这里插入图片描述
问题分析:

TypeError

错误1:MySQLdb._exceptions.ProgrammingError: not all arguments converted during bytes

#!/usr/bin/env python
#coding:utf-8
#导入连接数据库模块
import MySQLdb
#创建连接数据库链接
conn = MySQLdb.connect(host='127.0.0.1',user='root',passwd='123456',db='day05')
cur = conn.cursor()
#定义数据库操作,reCount返回执行sql语句影响的条数。
#reCount = cur.execute('select id,name from  userInfo')
#定义数据库操作,插入新数据
sql = 'update userInfo set name ="%s" where id =1'
params = ('dfq1')
#执行sql语句,但此时数据库并未插入新数据,因为执行的sql语句未添加到数据库,需执行commit操作
reCount = cur.execute(sql,params)
#执行commit方法,提交sql语句(如insert、update、delete等)请求
#执行一次commit方法可以同时提交多条sql语句。
conn.commit()
#获取数据库操作返回的数据
data = cur.fetchall()
#关闭数据库链接
cur.close()
conn.close()
print(data)
'''
log:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\MySQLdb\cursors.py", line 204, in execute
    query = query % args
TypeError: not all arguments converted during bytes formatting

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\backupAll\eclipseRoot\project001\main\index.py", line 14, in <module>
    reCount = cur.execute(sql,params)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\MySQLdb\cursors.py", line 206, in execute
    raise ProgrammingError(str(m))
MySQLdb._exceptions.ProgrammingError: not all arguments converted during bytes formatting
'''

解决方法
在这里插入图片描述
如上图红圈所示,python代码应为

params = ('dfq1',)

当params = (‘dfq1’)时,params不代表只包含一个元素的元组,代表元组params,对元组params内里每个值都单独格式化,params有两个值,因为"%s"仅有一个,所以报错。;当params = (‘dfq1’,)时,params代表只包含一个元素的元组,因为"%s"只有一个,所以不会报错。
用逗号","连接起来的代表是个序列/元组。
请参考:https://segmentfault.com/q/1010000000334606

错误2:TypeError: a bytes-like object is required, not ‘str’

#!/usr/bin/env python
#coding:utf-8
import socket

#创建socket对象,"socket对象 = socket模块.socket类"
socketObj = socket.socket()
#socket绑定监听地址
bindAddress = ('127.0.0.1',9999)
socketObj.bind(bindAddress)
#设置socket最大连接数
socketObj.listen(5)
#使用"socketObj.accept()"接收请求,获取客户端连接对象clientConnObj和客户端地址clientAddress
clientConnObj,clientAddress = socketObj.accept()
#向客户端发送信息
clientConnObj.send('hello,socket')
#关闭socket
clientConnObj.close()
'''
log:
Traceback (most recent call last):
  File "D:\backupAll\eclipseRoot\20190903LearnSocket\socketDemo\server.py", line 15, in <module>
    clientConnObj.send('hello,socket')
TypeError: a bytes-like object is required, not 'str'
'''

解决方法
python3较python2而言,最重要的新特性就是对文本和二进制数据做了更清晰的区分。文本用unicode编码,为str类型,二进制数据则为bytes类型。
python有两种类型转换的函数encode()和decode() 。 encode(编码),可以将str类型编码为bytes类型。 decode(译码),可以将bytes类型转换为str类型。
依据log提示,此处需要encode函数将str类型转化为bytes类型。
如下代码段所示:

messageStr = "hello,socket"
messageObj = messageStr.encode(encoding='utf_8', errors='strict')
clientConnObj.send(messageObj)

错误3:TypeError: ‘module’ object is not callable

错误示例:

#!/usr/bin/env python
#coding:utf-8
from multiprocessing import process
import queue
def f(q,n):
    q.put([n,'hello'])
if __name__ == "__main__":
    q = queue()
    for i in range(5):
        p = process(target=f,args=(q,i))
        p.start()
    print(q.get())
'''
log:
Traceback (most recent call last):
  File "D:\backupAll\eclipseRoot\20190909LearnMultithreading\main\multiprocessingDemo3.py", line 8, in <module>
    q = queue()
TypeError: 'module' object is not callable

'''

问题分析:
Python导入模块的方法有两种:import module 和 from module import,区别是前者所有导入的东西使用时需加上模块名的限定,而后者不要。
解决方法:
在这里插入图片描述
参考资料:https://blog.csdn.net/qq_36396104/article/details/82812461

错误4:TypeError: write() argument must be str, not bytes

错误示例:
interactive.py

# Copyright (C) 2003-2007  Robey Pointer <robeypointer@gmail.com>
#
# This file is part of paramiko.
#
# Paramiko is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# Paramiko is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.


import socket
import sys
from paramiko.py3compat import u

# windows does not have termios...
try:
    import termios
    import tty

    has_termios = True
except ImportError:
    has_termios = False


def interactive_shell(chan):
    if has_termios:
        posix_shell(chan)
    else:
        windows_shell(chan)


def posix_shell(chan):
    import select

    oldtty = termios.tcgetattr(sys.stdin)
    try:
        tty.setraw(sys.stdin.fileno())
        tty.setcbreak(sys.stdin.fileno())
        chan.settimeout(0.0)

        while True:
            r, w, e = select.select([chan, sys.stdin], [], [])
            if chan in r:
                try:
                    x = u(chan.recv(1024))
                    if len(x) == 0:
                        sys.stdout.write("\r\n*** EOF\r\n")
                        break
                    sys.stdout.write(x)
                    sys.stdout.flush()
                except socket.timeout:
                    pass
            if sys.stdin in r:
                x = sys.stdin.read(1)
                if len(x) == 0:
                    break
                chan.send(x)

    finally:
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)


# thanks to Mike Looijmans for this code
def windows_shell(chan):
    import threading

    sys.stdout.write(
        "Line-buffered terminal emulation. Press F6 or ^Z to send EOF.\r\n\r\n"
    )

    def writeall(sock):
        while True:
            data = sock.recv(256)
            if not data:
                sys.stdout.write("\r\n*** EOF ***\r\n\r\n")
                sys.stdout.flush()
                break
            sys.stdout.write(data)
            sys.stdout.flush()

    writer = threading.Thread(target=writeall, args=(chan,))
    writer.start()

    try:
        while True:
            d = sys.stdin.read(1)
            if not d:
                break
            chan.send(d)
    except EOFError:
        # user hit ^Z or F6
        pass
'''
log:
Hostname: 192.168.1.223
*** Unable to open host keys file
*** WARNING: Unknown host key!
Username [Administrator]: root
Auth by (p)assword, (r)sa key, or (d)ss key? [p] p
Warning: Password input may be echoed.
Password for root@ 192.168.1.223: yibotong
*** Here we go!

Line-buffered terminal emulation. Press F6 or ^Z to send EOF.



<class 'bytes'>
Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "D:\backupAll\eclipseRoot\20190909LearnMultithreading\paramiko-master\demos\interactive.py", line 88, in writeall
    sys.stdout.write(data)
TypeError: write() argument must be str, not bytes
'''

问题分析:
如上所示,在代码段中使用’print(type(data))‘的输出结果为’<class ‘bytes’>'类型,此处需要将bytes类型转化为str类型,如下所示。
解决方法:
如下所示,使用’data = dataOrigin.decode()'将bytes类型转化为str类型即可。
在这里插入图片描述

错误5:TypeError: ‘str’ object is not callable

错误实例:

#!/usr/bin/env python
#coding:utf-8
#处理与账户相关的文件
from test.test_decimal import file
def login():
    f = file("D:\backupAll\eclipseRoot\20190917LearnMVCDemo\View\index14.html","r")
    data = f.read()
    return data
    print(data)
        
if __name__ == "__main__":
    login()
'''
log:
Traceback (most recent call last):
  File "D:\backupAll\eclipseRoot\20190917LearnMVCDemo\Controller\account.py", line 20, in <module>
    login()
  File "D:\backupAll\eclipseRoot\20190917LearnMVCDemo\Controller\account.py", line 6, in login
    f = file("D:\backupAll\eclipseRoot\20190917LearnMVCDemo\View\index14.html","r")
TypeError: 'str' object is not callable
'''

问题分析:
解决方法:
此处我没有去解决,而是换了一种文件打开读取方法

```python
#!/usr/bin/env python
#coding:utf-8
#处理与账户相关的文件
def login():
    fOpen = open('D:\\backupAll\\eclipseRoot\\20190917LearnMVCDemo\\View\\index14.html','r',encoding='utf-8')
    data = fOpen.read()
    return data

if __name__ == "__main__":
    login()

参考链接:

RuntimeError

错误1:RuntimeError: thread.init() not called

#!/usr/bin/env python
#coding:utf-8
#导入模块
from threading import Thread
#导入队列模块的队列类
from queue import Queue
#定义生产者类,向队列存放数据
class producer(Thread):
    #重写父类的构造函数__init__
    def __init__(self,name,queue):
        #name:生产者的名字
        #queue:存放数据的容器
        self.__Name = name
        self.__Queue = queue
        Thread.__init__(self)
    
    #重写父类的run函数
    def run(self):
        self.__Queue.put('someData')
        Thread.run(self)
        
#定义消费者类 , 从队列取出数据  
class consumer(Thread):
    #重写父类的构造函数__init__
    def __init__(self,name,queue):
        #name:生产者的名字
        #queue:存放数据的容器
        self.__Name = name
        self.__Queue = queue
        #Thread.__init__(self)
        
    def run(self):
        self.__Queue.get()
        Thread.run(self)
        
queueObjTwo = Queue(maxsize=100)
#使用生产者类创建生产者对象。因为本质上是继承了线程类Thread,所以可以认为创建的生产者对象就等同于创建的新的线程
producerOne = producer('producerYiHao',queueObjTwo)
producerOne.start()
print(queueObjTwo.queue)
#使用消费者类创建消费者对象。因为本质上是继承了线程类Thread,所以可以认为创建的消费者对象就等同于创建的新的线程
consumerOne = consumer('consumerYiHao',queueObjTwo)
consumerOne.start()
'''
log
deque(['1'])
False
1
deque([])
True
deque(['someData'])
Traceback (most recent call last):
  File "D:\backupAll\eclipseRoot\20190905LearnThread\producerDemo\producer.py", line 58, in <module>
    consumerOne.start()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\threading.py", line 839, in start
    raise RuntimeError("thread.__init__() not called")
RuntimeError: thread.__init__() not called
'''

错误分析:
因为使用"producerOne.start()“启动线程时调用了父类Thread的start方法,而start方法与父类Thread的构造函数__init__有联系。重写构造函数__init__后,联系断裂而出错,因此需要在重写的构造函数加入对父类构造函数的调用。
解决方法:
在重写构造函数__init__时,在构造函数的最后一行应添加"Thread._init_(self)”,保留父类Thread构造函数的调用,如下图所示。

class producer(Thread):
    #重写父类的构造函数__init__
    def __init__(self,name,queue):
        #name:生产者的名字
        #queue:存放数据的容器
        self.__Name = name
        self.__Queue = queue
        
        super(producer,self).__init__()
        #或 Thread.__init__(self)
        

UnboundLocalError

错误1:UnboundLocalError: local variable ‘num’ referenced before assignment

错误示例

#!/usr/bin/env python
#coding:utf-8
#定义全局变量
num = 0
#定义函数
def run(n):
    print(n)
    num += 1 
    
run('dd')
'''
log:
dd
Traceback (most recent call last):
  File "D:\backupAll\eclipseRoot\20190905LearnThread\threadModule\threadLock.py", line 10, in <module>
    run('dd')
  File "D:\backupAll\eclipseRoot\20190905LearnThread\threadModule\threadLock.py", line 8, in run
    num += 1 
UnboundLocalError: local variable 'num' referenced before assignment
'''

解决方法
方法一,在函数run内部把变量num声明为局部变量,与函数run外的全局变量num独立起来。

#!/usr/bin/env python
#coding:utf-8
#定义全局变量
num = 0
#定义函数
def run(n):
    print(n)
    num = 10
    num += 1 
    print(num)
    
run('dd')

方法二,在函数run内部使用’global’声明变量num为全局变量,此时函数run内外变量num属于同一个。

#!/usr/bin/env python
#coding:utf-8
#定义全局变量
num = 0
#定义函数
def run(n):
    print(n)
    global num
    num += 1 
    print(num)
    
run('dd')

问题分析:
在以上错误示例代码中。变量num在函数run外被声明为全局变量,在函数run里面未声明为局部变量去使用,因为变量num在作为函数内局部变量使用前已经声明为全局变量,所以报错。即因为在函数内部尝试去修改函数外部的全局变量而出错。

ImportError

错误1:ImportError: cannot import name ‘Pool’

错误示例:
程序框架
在这里插入图片描述
multiprocessing .py

#!/usr/bin/env python
#coding:utf-8
from multiprocessing import Pool
import time
def f(x):
    time.sleep(1)
    print(x)
    print(x*x)
if __name__ == "__main__":
    p = Pool(5)
    print(p.map(f,range(100)))
'''
log:
Traceback (most recent call last):
  File "D:\backupAll\eclipseRoot\20190909LearnMultithreading\main\multiprocessing.py", line 3, in <module>
    from multiprocessing import Pool
  File "D:\backupAll\eclipseRoot\20190909LearnMultithreading\main\multiprocessing.py", line 3, in <module>
    from multiprocessing import Pool
ImportError: cannot import name 'Pool'
'''    

问题分析:
如上图程序框架和错误示例所示,由于"from multiprocessing import Pool"代码中使用的模块名与当前编辑的python文件名"multiprocessing .py"同名,所以抛出以上错误。
解决方法:
重命名当前编辑的python文件名"multiprocessing .py"为"multiprocessingDemo.py"即可。如下图所示。
在这里插入图片描述

PermissionError

PermissionError: [WinError 5] 拒绝访问。

错误示例:

#!/usr/bin/env python
#coding:utf-8
from multiprocessing import Process
import queue
def f(q,n):
    q.put([n,'hello'])
if __name__ == "__main__":
    q = queue.Queue()
    for i in range(4):
        p = Process(target=f,args=(q,i))
        p.start()
    print(q.get())
'''
log:
Traceback (most recent call last):
  File "D:\backupAll\eclipseRoot\20190909LearnMultithreading\main\multiprocessingDemo3.py", line 11, in <module>
    p.start()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\process.py", line 105, in start
    self._popen = self._Popen(self)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\popen_spawn_win32.py", line 65, in __init__
    reduction.dump(process_obj, to_child)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
TypeError: can't pickle _thread.lock objects
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\spawn.py", line 99, in spawn_main
    new_handle = reduction.steal_handle(parent_pid, pipe_handle)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\reduction.py", line 87, in steal_handle
    _winapi.DUPLICATE_SAME_ACCESS | _winapi.DUPLICATE_CLOSE_SOURCE)
PermissionError: [WinError 5] 拒绝访问。

'''

问题分析:
如上代码段所示,"from multiprocessing import Process,Queue"和"import queue"两种方式所引入的queue是不同的,此处应该使用前者。
解决方法:
如下图所示,使用"from multiprocessing import Process,Queue"便运行正常了。

#!/usr/bin/env python
#coding:utf-8
from multiprocessing import Process,Queue

def f(q,n):
    q.put([n,'hello'])
if __name__ == "__main__":
    q = Queue()
    for i in range(5):
        p = Process(target=f,args=(q,i))
        p.start()
    print(q.get())
'''
log:
[0, 'hello']
'''

参考资料:
https://blog.csdn.net/abcabc77777/article/details/79543307

RuntimeError

错误1:An attempt has been made to start a new process before the current process has finished its bootstrapping phase.

错误示例:

#!/usr/bin/env python
#coding:utf-8
from multiprocessing import Process

def run(info_list,n):
    info_list.append(n)
    print(info_list)
    
info = []
#启动十个进程
for i in range(1):
    p = Process(target=run,args=[info,i])
    p.start()
'''
log:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\spawn.py", line 114, in _main
    prepare(preparation_data)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\spawn.py", line 225, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
    run_name="__mp_main__")
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\backupAll\eclipseRoot\20190909LearnMultithreading\main\multiprocessingDemo3.py", line 13, in <module>
    p.start()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\process.py", line 105, in start
    self._popen = self._Popen(self)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\popen_spawn_win32.py", line 33, in __init__
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\spawn.py", line 143, in get_preparation_data
    _check_not_importing_main()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main
    is not going to be frozen to produce an executable.''')
RuntimeError: 
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.

'''

问题分析:
翻译以上的log即可。
解决方法:
如下图所示,添加一个主文件 的判断语句即可。
在这里插入图片描述

AssertionError

错误1:AssertionError: write() argument must be a bytes instance

错误示例:

#!/usr/bin/env python
#coding:utf-8
from wsgiref.simple_server import make_server
def runServer(environ,start_respose):
    start_respose(("200 OK"),[(("Content-Type"),("text/html"))])
    strObj = "<h1>hello ,wsgire<h1>"
    return strObj.encode(encoding='utf_8', errors='strict')
if __name__ == "__main__":
    httpd = make_server("", 8001, runServer)
    print("serving http on port 8001....")
    httpd.serve_forever()
'''
log:
serving http on port 8001....
127.0.0.1 - - [17/Sep/2019 11:33:59] "GET / HTTP/1.1" 200 0
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 138, in run
    self.finish_response()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 266, in write
    "write() argument must be a bytes instance"
AssertionError: write() argument must be a bytes instance
127.0.0.1 - - [17/Sep/2019 11:33:59] "GET / HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 53366)
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 138, in run
    self.finish_response()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 266, in write
    "write() argument must be a bytes instance"
AssertionError: write() argument must be a bytes instance

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 141, in run
    self.handle_error()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 368, in handle_error
    self.finish_response()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 274, in write
    self.send_headers()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 331, in send_headers
    if not self.origin_server or self.client_is_modern():
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 344, in client_is_modern
    return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 317, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 348, in process_request
    self.finish_request(request, client_address)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 721, in __init__
    self.handle()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\simple_server.py", line 133, in handle
    handler.run(self.server.get_app())
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 144, in run
    self.close()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\simple_server.py", line 35, in close
    self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------
127.0.0.1 - - [17/Sep/2019 11:33:59] "GET / HTTP/1.1" 200 0
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 138, in run
    self.finish_response()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 266, in write
    "write() argument must be a bytes instance"
AssertionError: write() argument must be a bytes instance
127.0.0.1 - - [17/Sep/2019 11:33:59] "GET / HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 53367)
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 138, in run
    self.finish_response()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 266, in write
    "write() argument must be a bytes instance"
AssertionError: write() argument must be a bytes instance

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 141, in run
    self.handle_error()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 368, in handle_error
    self.finish_response()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 274, in write
    self.send_headers()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 331, in send_headers
    if not self.origin_server or self.client_is_modern():
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 344, in client_is_modern
    return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 317, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 348, in process_request
    self.finish_request(request, client_address)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 721, in __init__
    self.handle()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\simple_server.py", line 133, in handle
    handler.run(self.server.get_app())
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 144, in run
    self.close()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\simple_server.py", line 35, in close
    self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------
127.0.0.1 - - [17/Sep/2019 11:33:59] "GET / HTTP/1.1" 200 0
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 138, in run
    self.finish_response()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 266, in write
    "write() argument must be a bytes instance"
AssertionError: write() argument must be a bytes instance
127.0.0.1 - - [17/Sep/2019 11:33:59] "GET / HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 53365)
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 138, in run
    self.finish_response()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 266, in write
    "write() argument must be a bytes instance"
AssertionError: write() argument must be a bytes instance

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 141, in run
    self.handle_error()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 368, in handle_error
    self.finish_response()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 274, in write
    self.send_headers()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 331, in send_headers
    if not self.origin_server or self.client_is_modern():
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 344, in client_is_modern
    return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 317, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 348, in process_request
    self.finish_request(request, client_address)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 721, in __init__
    self.handle()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\simple_server.py", line 133, in handle
    handler.run(self.server.get_app())
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 144, in run
    self.close()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\simple_server.py", line 35, in close
    self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------
127.0.0.1 - - [17/Sep/2019 11:34:00] "GET / HTTP/1.1" 200 0
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 138, in run
    self.finish_response()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 266, in write
    "write() argument must be a bytes instance"
AssertionError: write() argument must be a bytes instance
127.0.0.1 - - [17/Sep/2019 11:34:00] "GET / HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 53374)
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 138, in run
    self.finish_response()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 266, in write
    "write() argument must be a bytes instance"
AssertionError: write() argument must be a bytes instance

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 141, in run
    self.handle_error()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 368, in handle_error
    self.finish_response()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 274, in write
    self.send_headers()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 331, in send_headers
    if not self.origin_server or self.client_is_modern():
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 344, in client_is_modern
    return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 317, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 348, in process_request
    self.finish_request(request, client_address)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 721, in __init__
    self.handle()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\simple_server.py", line 133, in handle
    handler.run(self.server.get_app())
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\handlers.py", line 144, in run
    self.close()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\wsgiref\simple_server.py", line 35, in close
    self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------

'''

问题分析:
data是int 类型,转成bytes类型
解决方法:

try:
            if not self.result_is_file() or not self.sendfile():
                for data in self.result:
                    self.write(bytes(data))
                self.finish_content()
        finally:
            self.close()

参考资料:
https://www.delftstack.com/howto/python/how-to-convert-int-to-bytes-in-python-2-and-python-3/

OSError

错误1:OSError: [Errno 22] Invalid argument: ‘D:\x08ackupAll\eclipseRoot\x8190917LearnMVCDemo\View\index14.html’

错误示例:

#!/usr/bin/env python
#coding:utf-8
#处理与账户相关的文件
def login():
    fOpen = open("D:\backupAll\eclipseRoot\20190917LearnMVCDemo\View\index14.html",'r',encoding="utf-8")
    data = fOpen.read()
    #return data
    print(data)

if __name__ == "__main__":
    login()
'''
log:
Traceback (most recent call last):
  File "D:\backupAll\eclipseRoot\20190917LearnMVCDemo\Controller\account.py", line 19, in <module>
    login()
  File "D:\backupAll\eclipseRoot\20190917LearnMVCDemo\Controller\account.py", line 5, in login
    fOpen = open("D:\backupAll\eclipseRoot\20190917LearnMVCDemo\View\index14.html",'r',encoding="utf-8")
OSError: [Errno 22] Invalid argument: 'D:\x08ackupAll\\eclipseRoot\x8190917LearnMVCDemo\\View\\index14.html'

'''

问题分析:
这是由于window系统上的路径表示符号""引起的
解决方法:

fOpen = open("D:\backupAll\eclipseRoot\20190917LearnMVCDemo\View\index14.html",'r',encoding="utf-8")

改为

fOpen = open('D:\\backupAll\\eclipseRoot\\20190917LearnMVCDemo\\View\\index14.html','r',encoding='utf-8')

参考资料:
https://blog.csdn.net/qq_42393859/article/details/88018824

NameError

错误1:NameError: name ‘HttpResponse’ is not defined

错误示例:

from django.shortcuts import render

# Create your views here.

#定义index函数
def index(request):
    #返回index字符串
    return HttpResponse("index")
'''
log:
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 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.
September 17, 2019 - 22:18:44
Django version 2.2.5, using settings 'LearnDjangoDemo.settings'
Starting development server at http://0.0.0.0:9000/
Quit the server with CTRL-BREAK.
Not Found: /
[17/Sep/2019 22:18:49] "GET / HTTP/1.1" 404 2036
[17/Sep/2019 22:18:55] "GET /index HTTP/1.1" 301 0
Internal Server Error: /index/
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "D:\backupAll\eclipseRoot\LearnDjangoDemo\web\views.py", line 8, in index
    return HttpResponse("index")
NameError: name 'HttpResponse' is not defined
[17/Sep/2019 22:18:55] "GET /index/ HTTP/1.1" 500 65691
Internal Server Error: /index/
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "D:\backupAll\eclipseRoot\LearnDjangoDemo\web\views.py", line 8, in index
    return HttpResponse("index")
NameError: name 'HttpResponse' is not defined
[17/Sep/2019 22:19:00] "GET /index/ HTTP/1.1" 500 65691

'''

问题分析:
因为你没有导入HttpResponse。需要在views.py的顶部添加:
from django.shortcuts import HttpResponse
解决方法:

参考资料:
https://zhidao.baidu.com/question/204322758404839925.html

AttributeError

错误1:AttributeError : ‘str’ object has no attribute ‘tzinfo’

错误示例:
问题分析:
数据库中的数据中所具备的datetime属性,其值异常,如“0000-00-00 00:00:00”.
解决方法:
方法一:手动改一下datetime属性的值,改成今天就行。
参考文献:
https://blog.csdn.net/zhaojikun521521/article/details/83825026
https://blog.csdn.net/weixin_42190107/article/details/92074222

其他

参考文献:
https://blog.csdn.net/sjpljr/article/details/102953316/

错误2:AttributeError: ‘str’ object has no attribute ‘tzinfo’

解决方法:
在这里插入图片描述参考文献:
https://www.cnblogs.com/wangyuxing/p/12696670.html

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值