我是靠谱客的博主 曾经悟空,最近开发中收集的这篇文章主要介绍Traceback (most recent call last):,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Server part code:

#!/usr/bin/env python
from socket import *
from time import ctime
HOST=''
PORT=21567
BUFFSZ=1024
ADDR=(HOST,PORT)
tcpSerSock = socket(AF_INET, SOCK_STREAM)
tcpSerSock.bind(ADDR)
tcpSerSock.listen(5)
while True:
print("Waiting for connection...")
tcpCliSock, addr=tcpSerSock.accept()
print('...connected from:', addr)
while True:
data = tcpCliSock.recv(BUFFSZ)
if not data:
print('Test')
break;
#tcpCliSock.send('[%s] %s' % (bytes(ctime(),'utf-8'),data))
tcpCliSock.send('[%s] %s' % (bytes(ctime(), 'utf-8'), data))
tcpCliSock.close()
tcpSerSock.close()

Client part code:

#!/usr/bin/env python
from socket import *
HOST='localhost'
PORT=21567
BUFFSZ=1024
ADDR=(HOST,PORT)
tcpCliSock=socket(AF_INET, SOCK_STREAM)
tcpCliSock.connect(ADDR)
while True:
data=raw_input('->')
if not data:
break;
tcpCliSock.send(data)
data=tcpCliSock.recv(BUFFSZ)
if not data:
break
print(data)
tcpCliSock.close()

error info:

[tcsh] hanwuwex@bjsxfrax001:/local/hanwuwex> python tsTserv3.py
Waiting for connection...
('...connected from:', ('127.0.0.1', 44290))
Traceback (most recent call last):
File "tsTserv3.py", line 26, in <module>
tcpCliSock.send('[%s] %s' % (bytes(ctime(), 'utf-8'), data))
TypeError: str() takes at most 1 argument (2 given)
[Linux]

Error occured at File “tsTserv3.py”, line 26, in
tcpCliSock.send(‘[%s] %s’ % (bytes(ctime(), ‘utf-8’), data)) which root cause is TypeError: str() takes at most 1 argument (2 given). So we should delete the configure item ‘utf-8’, so the finnally valid code as below show:
tcpCliSock.send(‘[%s] %s’ % (bytes(ctime()), data))

最后

以上就是曾经悟空为你收集整理的Traceback (most recent call last):的全部内容,希望文章能够帮你解决Traceback (most recent call last):所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(41)

评论列表共有 0 条评论

立即
投稿
返回
顶部