473,556 Members | 2,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

http request doesn't work!

Could someone please let me know what i'm doing wrong here:

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(WE B_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()
print data

The output of the above is different if you go to the following in
your browser:
Whats my problem?!?!??!
Jul 18 '05 #1
2 1711
ba**********@cl inicdesignNOSPA M.com.au wrote:
Could someone please let me know what i'm doing wrong here:

Using the obsolete httplib.HTTP class.


Try using HTTPConnection and HTTPResponse objects:
import httplib

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

http_conn = httplib.HTTPCon nection( webhost )
http_conn.reque st( 'GET', pagepath )

http_resp = http_conn.getre sponse()
( http_resp.statu s, http_resp.reaso n )

(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
The output of the above is different if you go to the following in
your browser:
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.

Jul 18 '05 #3

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

Similar topics

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. # No warranty express or implied for the accuracy, fitness to purpose
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 arguments being used, and then I use Javascript to se the IMG element's SRC property to the URL. I have discovered, that if the visitor clicks...
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 a wild-*ss_guess at how to do it but it doesn't work. (see code below) I get a error 400 response (bad request). Any advice on this would be greatly...
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" action="http://www.theirsite.htm"> <input type=hidden name="field1" value="value1"> <input type=hidden name="field2> value="value2> <input type="submit" value="Click Me"> On...
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 using IE6 and following url: But when I attempt a second connect the windows symbol in the upper right corner of ie starts in...
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" anywhere. I looked around and found a class called HttpWorkerRequest which has a method called GetHttpVersion() which returns the exact thing I am...
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 intranet. I need to have pages be reloaded automatically when the data they reflect is changed at the server. For Netscape/Mozilla/Firefox, I do...
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.... Thanks
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 checked require secure channel, require 128-bit encryption. In custom error, instead of using default message HTTP 403.4 - Forbidden: SSL required...
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 Request to retrieve the values, but POST doesn't work. There is NO Proxy... the only thing I can think is that ASP.NET is somehow filtering out the...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.