Trouble with PY4E Chapter 12, Understanding request/response cycle assignment. | Coursera Community
Coursera Header
Question

Trouble with PY4E Chapter 12, Understanding request/response cycle assignment.

  • 9 November 2019
  • 3 replies
  • 3397 views

Badge +1

HI there. This is my first question on this forum. So here we go.

In the exercise I modified the url in the socket1.py file as told to retrieve the document from the link provided. But after doing all and running in cmd, I get ‘socket.gaierror: [Errno 11001] getaddrinfo failed’ error. I also can’t get to work this with the other alternative methods i.e., browser developer console and telnet. Telnet throws a ‘Could not open connection to the host, on port 80: Connect failed’ error. I looked into google but not getting a clear answer. It would really help if someone solved this issue for me. I’m also putting in the code.

 

import socket

mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('http://data.pr4e.org/intro-short.txt', 80))
cmd = 'GET http://data.pr4e.org/intro-short.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='')

mysock.close()


3 replies

Badge +1

Questions for specific course should be directed to the Discussion Forum of that particular course if you look at the specific course, and you would see the available Discussion Forum for each course including the Week that have all kinds of questions for that particular course. You may want to do read through the comments of the specific Discussion Forum before asking your questions if there are questions already answered. And every course has its own Discussion Forum since the people who put the course together know how to answer your questions related to that specific courses, which make sense. Hope this help.

 

https://www.coursera.org/learn/python-network-data/discussions

Userlevel 1
Badge +2

Hi  Vishal,

I understood your question better to go through the course videos and notes in coursera they will be given  .And if you  have time to read the textbook,  take “Head First Python Text  book”or download from the internet  it is available and you can find the solution from  the given code  or as per said “YEN”   once see the discussion you can  solve for your question.

Badge

Just correct this line

mysock.connect(('http://data.pr4e.org/intro-short.txt', 80))

to

mysock.connect(('data.pr4e.org', 80))

first parameter is just the host to connect to the server

 

Reply