473,322 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

http request doesn't work!

Could someone please let me know what i'm doing wrong here:
#!/usr/bin/python

import httplib

WEB_SITE = 'adsl.internode.on.net'
#WEB_SITE = 'www.google.com'
#PAGE_PATH = '/about.html'
PAGE_PATH = '/htm/un-metered-sites-ip-list.htm'
http = httplib.HTTP(WEB_SITE)
http.putrequest('GET', PAGE_PATH)
http.putheader('Accept', 'text/html')
http.putheader('Accept', 'text/plan')
http.endheaders()
httpcode, httpmsg, headers = http.getreply()
print 'msg: ' + httpmsg
print httpcode
doc = http.getfile()
data = doc.read()
doc.close()
print data


The output of the above is different if you go to the following in
your browser:
http://adsl.internode.on.net/htm/un-...es-ip-list.htm
Whats my problem?!?!??!
Jul 18 '05 #1
2 1702
ba**********@clinicdesignNOSPAM.com.au wrote:
Could someone please let me know what i'm doing wrong here:


Using the obsolete httplib.HTTP class.

<http://www.python.org/doc/lib/module-httplib.html>

Try using HTTPConnection and HTTPResponse objects:
import httplib

webhost = 'adsl.internode.on.net'
pagepath = '/htm/un-metered-sites-ip-list.htm'

http_conn = httplib.HTTPConnection( webhost )
http_conn.request( 'GET', pagepath )

http_resp = http_conn.getresponse()
( http_resp.status, http_resp.reason )

(200, 'OK')

--
\ "I stayed up all night playing poker with tarot cards. I got a |
`\ full house and four people died." -- Steven Wright |
_o__) |
Ben Finney <http://bignose.squidly.org/>
Jul 18 '05 #2
f29
>
The output of the above is different if you go to the following in
your browser:
http://adsl.internode.on.net/htm/un-...es-ip-list.htm
Whats my problem?!?!??!


Try adding User-Agent header of some popular browser (e.g.
"Mozilla/5.0 (Windows; U; Windows NT; en-US; rv:1.6) Gecko") so that
remote site could not prevent fetching their content with a robot.

Moreover, try looking at the urllib2 module, it has great power.

rgrds,
f29
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
2
by: Robert Oschler | last post by:
I have an IMG element that I've been using to send messages back to my server whenever certain item option choices are made by a visitor. I send each message by forming a URL with various search...
3
by: Ron Slosberg | last post by:
Hi, I am trying to download a file from a web page in code. I cannot use the System.Net.WebClient DownloadFile method because in order to get the file i must POST a request with form fields. Took...
6
by: Phillip N Rounds | last post by:
I have a webform, from which I have to submit info to another site. Their instructions are to have a html form, with the following as the submit: <form method="post"...
6
by: Microsoft News | last post by:
Hi, I have been using several http server code examples from the web, include one from msdn, and I can't seem to get a simple http server thread working. I can connect the server successful...
1
by: Juan Dent | last post by:
Hi, The Request.SaveAs method stores in a file the complete HTTP request including the HttpVersion. However when I try to reproduce in memory the same thing, I cannot find the "HTTP/1.1"...
11
by: Steve Kirkendall | last post by:
I need a work-around for an IE limitation, regarding fetching HTTP documents in the background. It takes a bit of explaining; please be patient... I'm working on an project that will run on an...
10
by: rup | last post by:
Hello, This is my first application on socket programming in vc++. I am facing problem that how to make connection to server, & make GET/POST request by HTTP. Please help me. Its urgent.......
7
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I am trying to set this up using asp code and IIS configuration. But it seems not working. Here it is the way I am doing. In IIS I set up a virtual directory with secure communication, I...
1
by: ERobishaw | last post by:
Using Winform app writing a HTTP Post using the following... on the server side, I get no form fields. Request.Form.AllKeys.Length = 0. If I put the field/value paris in the URL I can use...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.