python winerror 10065_python:winerror 10045:引用的对象类型不支持尝试的操作

我正在使用客户机/服务器程序创建一个caesar密码程序。客户端将输入消息和密钥,服务器将返回密码文本。这是我的服务器代码:

import socket

def getCaesar(message, key):

cipher = ""

for i in message:

char = message[i]

# Encrypt uppercase characters

if (char.isupper()):

cipher += chr((ord(char) + key-65) % 26 + 65)

# Encrypt lowercase characters

else:

cipher += chr((ord(char) + key - 97) % 26 + 97)

return cipher

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

host=socket.gethostname()

port=4000

s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

s.bind((host,port))

s.listen(5)

print("Listenting for requests")

while True:

s,addr=s.accept()

print("Got connection from ",addr)

print("Receiving...")

message,key=s.recv(1024)

resp=getCaesar(message, key)

s.send(resp)

s.close()

错误消息调用此行:s.send(消息,键),并显示以下错误:

oserror:[winerror 10045]引用的对象类型不支持尝试的操作。这个错误是什么意思?

我的客户代码:

import socket

def getMessage():

print('Enter your message:')

return input()

def getKey():

key = 0

while True:

print('Enter the key number (1-%s)' % (26))

key = int(input())

if (key >= 1 and key <= 26):

return key

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

host=socket.gethostname()

port=4000

s.connect((host,port))

message = getMessage()

key = getKey()

message=message.encode()

s.send(message, key)

cipher= s.recv(1024)

print('Ciphertext: ')

print(cipher)

s.close()

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值