python不支持的函数string_为什么Python不能识别string类型的format函数?

尝试运行Python套接字http服务器时出错。在import SocketServer

class MyTCPHandler(SocketServer.BaseRequestHandler):

"""

The RequestHandler class for our server.

It is instantiated once per connection to the server, and must

override the handle() method to implement communication to the

client.

"""

def handle(self):

# self.request is the TCP socket connected to the client

self.data = self.request.recv(1024).strip()

print "{} wrote:".format(self.client_address[0])

print self.data

# just send back the same data, but upper-cased

self.request.send(self.data.upper())

if __name__ == "__main__":

HOST, PORT = "localhost", 9999

# Create the server, binding to localhost on port 9999

server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)

# Activate the server; this will keep running until you

# interrupt the program with Ctrl-C

server.serve_forever()

错误:

^{pr2}$

我的委托人:import socket

import sys

HOST, PORT = "localhost", 9999

data = " ".join(sys.argv[1:])

# Create a socket (SOCK_STREAM means a TCP socket)

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:

# Connect to server and send data

sock.connect((HOST, PORT))

sock.send(data + "\n")

# Receive data from the server and shut down

received = sock.recv(1024)

finally:

sock.close()

print "Sent: {}".format(data)

print "Received: {}".format(received)

这里怎么了?在

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值