I was taking the lecture on coursera and replicate the code written in the lecture video but somehow it doesn't work. The code tries to retrieve the data from a web page but got a type error.
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('www.py4inf.com', 80))
mysock.send('GET http://www.py4inf.com/code/romeo.txt HTTP/1.0\n\n')
while True:
data = mysock.recv(512)
if(len(data)< 1):
break
print(data)
mysock.close()
Error goes like this:
Traceback (most recent call last):
File "cheese.py", line 4, in <module>
mysock.send('GET http://www.py4inf.com/code/romeo.txt HTTP/1.0\n\n')
TypeError: a bytes-like object is required, not 'str'