TypeError: 'bytes' object is not callable解决办法

来源:互联网 发布:sql创建学生数据库 编辑:程序博客网 时间:2024/06/16 09:15

python 遇到这个问题:

源码如下

# 导入 socket、sys 模块import socketimport sys# 创建 socket 对象serversocket = socket.socket(            socket.AF_INET, socket.SOCK_STREAM) port = 80serversocket.bind(('127.0.0.1', port))# 设置最大连接数,超过后排队serversocket.listen(5)while True:    # 建立客户端连接    clientsocket,addr = serversocket.accept()          print("连接地址: %s" %str(addr))    str = clientsocket.recv(1024)    print(str1)    #msg='欢迎访问菜鸟教程!'+ "\r\n"    msg = 'HTTP/1.1 200 OK\r\nContent-Type: text/html;charset=ISO-8859-1\r\nContent-Length: 500\r\n\r\n<html>\r\n<head>\r\n<title> hello word it is my first try</title>\r\n</head>\r\n<body>\r\n<h2>\r\n hello word it is my first try</h2>\r\n</body>\r\n</html>\r\n'    clientsocket.send(msg.encode('utf-8'))    print("dfsdf")    clientsocket.close()    #while True:    #pass

报错如下:

raceback (most recent call last):
  File "E:\Data\Coding\python\socke.py", line 17, in <module>
    print("连接地址: %s" %str(addr))
TypeError: 'bytes' object is not callable


因为这个函数里调用了str(addr),而后面定义了字符串str.循环执行第二次的时候会报这个错,

这时候把str 当bytes,报错,该对象不可调用(不是函数)

0 0
原创粉丝点击