Networking: Write a Web Browser

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(('', 80))
cmd = 'GET HTTP/1.0\r\n\r\n'.encode()

while True:
    data = mysock.recv(512)
    if len(data) < 1:

This code works fine on Google Colab. It could be a firewall or something on your local system or network blocking.

Try allowing the app through the firewall?

Actually the firewall doesn’t make sense since you are receiving a response from the server. In your screenshot cmd only has \n\n

I’m able to replicate your error with \n\n:

Thanks for checking this out for me. I guess the carriage returns are essential for a properly constructed request then!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.