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 6236123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:47:41+00:00 2026-05-24T10:47:41+00:00

i am new to python and am trying my luck at sockets. So i

  • 0

i am new to python and am trying my luck at sockets. So i wrote a simple http client but to my surprise it is failing to access webpages that firefox can access, yet they use the same headers

import socket
clientsocket= socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect(("213.229.83.205",80))#connect to proxy at given address
print "connected to 213.229.83.205"
sdata= """GET http://google.co.ug/ HTTP/1.1
Host: google.co.ug
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20100101 Firefox/6.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Proxy-Connection: keep-alive
Cookie: cookie <-- Real cookie deleted

"""
print "sending request"
clientsocket.send(sdata);
rdata=clientsocket.recv(10240)
if not rdata: print "no data found"
else:
    print "receiving data !"
    myfile=open("c:/users/markdenis/desktop/google.html","w")
    myfile.write(str(rdata))
    myfile.close()
    print "data written to file on desktop"
clientsocket.close()
raw_input()#system(pause)

When i run it, it shows:

connected to 213.229.83.205
sending request
no data found
  • 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-05-24T10:47:42+00:00Added an answer on May 24, 2026 at 10:47 am

    The HTTP protocol requires \r\n at the end of each header and an extra on a blank line at the end of the HTTP headers. You aren’t explicit about the line endings in your sdata buffer, and therefore your buffer ends up with just \n line endings.

    Tested on Windows, Linux and OS X, to be sure:

    >>> x = """a
    b
    c"""
    >>> x
    'a\\nb\\nc\\n'
    

    Where you need:

    >>> x = "a\r\nb\r\nc\r\n"
    >>> x
    'a\\r\\nb\\r\\nc\\r\\n'
    

    Add \r\ns and give it a shot. Doing it directly in the buffer will get you an extra set of \n, so split it up:

    sdata = "GET http://google.co.ug/ HTTP/1.1\r\n"
    sdata += "Host: google.co.ug\r\n"
    sdata += "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20100101 Firefox/6.0\r\n"
    sdata += "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
    sdata += "Accept-Language: en-us,en;q=0.5\r\n"
    sdata += "Accept-Encoding: gzip, deflate\r\n"
    sdata += "Proxy-Connection: keep-alive\r\n"
    sdata += "\r\n"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to python but I've run into a hitch when trying to implement
I am very new to python. I am trying to write a program that
I'm pretty new to Python and App Engine, but what I'm trying to do
I am new to Python and trying to build a practice project that reads
I'm new to python and is trying to install the pyimage module. http://code.google.com/p/pyimage/ I'm
I'm new to Python and I'm trying to create a simple GUI using Tkinter.
I am new to python and I'm trying to create a program that creates
I am new to python and essentially trying to figure out the syntax that
I'm new to python and I'm trying to make a search bar that searches
New to Python, but I'm trying to...retrieve data from a site: import urllib.request response

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.