脚本是为Python2编写的,但我需要将它转换为Python3。
结果:
Traceback (most recent call last):
File "tplink_smartplug.py", line 105, in <module>
sock_tcp.send(encrypt(cmd))
File "tplink_smartplug.py", line 70, in encrypt
result += chr(a)TypeError:不能将str连接到字节
# XOR Autokey Cipher with starting key = 171
def encrypt(string):
key = 171
result = pack('>I', len(string))
for i in string:
a = key ^ ord(i)
key = a
result += chr(a) #line70
return result
def decrypt(string):
key = 171
result = ""
for i in string:
a = key ^ ord(i)
key = ord(i)
result += chr(a)
return result# Send command and receive reply
try:
sock_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock_tcp.connect((ip, port))
sock_tcp.send(encrypt(cmd)) #line105
data = sock_tcp.recv(2048)
sock_tcp.close()
print(("Sent: ", cmd ))
print(("Received: ", decrypt(data[4:]) ))
except socket.error:
quit("Cound not connect to host " + ip + ":" + str(port))发布于 2020-01-04 08:16:51
是的,它已经修改为Python3 at GITHUB
https://stackoverflow.com/questions/57246029
复制相似问题