python网络中一元str的坏操作数类型

时间:2017-06-18 23:07:19

标签: python sockets cmd telnet

我正在学习绑定和监听套接字,所以当我写完代码通过cmd连接到给定的localhost时,会出现以下错误。

s.listen(5)

conn, addr = s.accept()

print('connected with: ', + addr[0] + ':' + str(addr[1]))

我收到以下错误:

Traceback (most recent call last):

  File "C:/Users/vineel/Desktop/Python34/PYTHON NETWORKING/bindsockets.py", line 19, in <module>

   print('connected with: ', + addr[0] + ':' + str(addr[1]))

TypeError: bad operand type for unary +: 'str'

1 个答案:

答案 0 :(得分:0)

print('connected with: ', + addr[0] + ':' + str(addr[1]))

应该是(不是逗号):

print('connected with: ' + addr[0] + ':' + str(addr[1]))