Python 错误:需要类似字节的对象,而不是';str';
我正在尝试此操作,它显示错误:Python 错误:需要类似字节的对象,而不是';str';,python,Python,我正在尝试此操作,它显示错误: TypeError Traceback (most recent call last) <ipython-input-16-085dfa8fff25> in <module> ----> 1 s.send(text) TypeError: a bytes-like object is required, not 'str' 造成此错误的原因是什么?我如何解决它?第4行中
TypeError Traceback (most recent call last)
<ipython-input-16-085dfa8fff25> in <module>
----> 1 s.send(text)
TypeError: a bytes-like object is required, not 'str'
造成此错误的原因是什么?我如何解决它?第4行中有一个问题在第4行中
b“GET/index.html HTTP/1.0\r\n\r\n”
工作?工作正常你能解释第4行的意思吗?第4行中有一个问题在第4行中b“GET/index.html HTTP/1.0\r\n\r\n”
工作正常吗?你能解释第4行的意思吗
from socket import *
s = socket(AF_INET,SOCK_STREAM)
s.connect(("www.python.org",80))
s.send("GET /index.html HTTP/1.0\r\n\r\n")
chunks = []
while True:
chunk = s.recv(16384)
if not chunk: break
chunks.append(chunk)
s.close()
response = "".join(chunks)
print (response)