错误:需要一个类似字节的对象,而不是'str'

时间:2019-02-15 05:29:21

标签: 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'

到目前为止我的方法:

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)

是什么导致此错误,我该如何解决?

0 个答案:

没有答案