Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7762231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:20:41+00:00 2026-06-01T14:20:41+00:00

I was learning socket programming and tried to design a basic http client of

  • 0

I was learning socket programming and tried to design a basic http client of mine. But somehow everything is going good but I am not receiving any data. Can you please tell me what am I missing?

CODE

import socket

def create_socket():
    return socket.socket( socket.AF_INET, socket.SOCK_STREAM )

def remove_socket(sock):
    sock.close()
    del sock


sock = create_socket()
print "Connecting"
sock.connect( ('en.wikipedia.org', 80) )
print "Sending Request"
print sock.sendall  ('''GET /wiki/List_of_HTTP_header_fields HTTP/1.1
Host: en.wikipedia.org
Connection: close
User-Agent: Web-sniffer/1.0.37 (+http://web-sniffer.net/)
Accept-Encoding: gzip
Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7
Cache-Control: no-cache
Accept-Language: de,en;q=0.7,en-us;q=0.3
Referer: d_r_G_o_s
''')
print "Receving Reponse"
while True:
    content = sock.recv(1024)
    if content:
        print content
    else:
        break
print "Completed"

OUTPUT

Connecting
Sending Request
298
Receving Reponse
Completed

While I was expecting it show me html content of homepage of wikipedia :'(

Also, it would be great if somebody can share some web resources / books where I can read in detail about python socket programming for HTTP Request Client

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:20:43+00:00Added an answer on June 1, 2026 at 2:20 pm

    For a minimal HTTP client, you definitely shouldn’t send Accept-Encoding: gzip — the server will most likely reply with a gzipped response you won’t be able to make much sense of by eye. 🙂

    You aren’t sending the final double \r\n (nor are you actually terminating your lines with \r\n as per the spec (unless you happen to develop on Windows with Windows line endings, but that’s just luck and not programming per se).

    Also, del sock there does not do what you think it does.

    Anyway — this works:

    import socket
    sock = socket.socket()
    sock.connect(('en.wikipedia.org', 80))
    for line in (
        "GET /wiki/List_of_HTTP_header_fields HTTP/1.1",
        "Host: en.wikipedia.org",
        "Connection: close",
    ):
        sock.send(line + "\r\n")
    sock.send("\r\n")
    
    while True:
        content = sock.recv(1024)
        if content:
            print content
        else:
            break
    

    EDIT: As for resources/books/reference — for a reference HTTP client implementation, look at Python’s very own httplib.py. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still learning socket programming (using Perl) but I have both options (
I'm just learning the basics of socket programming for C++, but I've heard people
I'm learning C# asynchronous socket programming, and I've learned that it's a good idea
I am learning objective C.I like to know about client/server(socket) programming for iphone. I
I'm learning socket programming (in python) and I was wondering what the best/typical way
I am learning socket programming for use in an upcoming project, and I have
I am learning socket programming in c and trying to understand what exactly is
I'm learning socket programming in C & downloaded a simple tcp server source file.
I'm learning socket programming and I have the following function: public void OnDataReceived(IAsyncResult asyn)
I am just learning socket programming and I am trying to write an echo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.