I’m trying to follow along with the Scientific Computing with Python course but I can’t get the example code to work for me in the step linked below.
Here’s a screenshot of the code in question, which includes the error returned by the server:
I don’t know what ‘45’ means and I don’t understand why I’m getting that error.
The url is fine, as it returns the expected response in a web browser.
I’m probably doing something fundamentally incorrect but I’m a Python newbie so don’t really understand what I’m doing.
Can anyone enlighten me please?
EDIT: Strangely, the following code (given at the end of the video) does work (perhaps because of the inclusion of the carriage returns in the request string):
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('data.pr4e.org', 80))
cmd = 'GET http://data.pr4e.org/romeo.txt HTTP/1.0\r\n\r\n'.encode()
mysock.send(cmd)
while True:
data = mysock.recv(512)
if len(data) < 1:
break
print(data.decode(),end='')


