473,473 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Getting server status response from HTTP request

First of all, I am a complete newbie to Python, but have been impressed
with how easy the language has been to pick up.

I am trying to write a script that checks to see if the web /
application server is up. I have the following code that works:

--
import httplib

try:
httpobj = httplib.HTTPConnection('www.domain.com', 80)
httpobj.connect();
httpobj.putrequest('GET', '/foo/ping.cfm')
httpobj.putheader('Accept', '*/*')
httpobj.endheaders()

reply = httpobj.getresponse()
httpobj.close();

if reply.status != 200:
print "There may be a problem with the server. Response Status :",
reply.status
else:
print "server is fine"

except Exception:
print "An exception occured"
--

I was curious if anyone had suggestions on a better way to do this. I
tried to use urllin2, but could not figure out how to retrieve the
status code.

mike c
Jul 18 '05 #1
1 2271
On Fri, 13 Feb 2004 10:36:44 -0800
Mike C <m@poo.com> wrote:
First of all, I am a complete newbie to Python, but have been impressed
with how easy the language has been to pick up.

I am trying to write a script that checks to see if the web /
application server is up. I have the following code that works:

--
import httplib

try:
httpobj = httplib.HTTPConnection('www.domain.com', 80)
httpobj.connect();
httpobj.putrequest('GET', '/foo/ping.cfm')
httpobj.putheader('Accept', '*/*')
httpobj.endheaders()

reply = httpobj.getresponse()
httpobj.close();

if reply.status != 200:
print "There may be a problem with the server. Response Status :",
reply.status
else:
print "server is fine"

except Exception:
print "An exception occured"
--

I was curious if anyone had suggestions on a better way to do this. I
tried to use urllin2, but could not figure out how to retrieve the
status code.

mike c


Suggestion...don't use a "GET" request, use a "HEAD" request. That way the server will only return the headers and not the complete file (the status code will be the same) so you can check any file you want using only a minimal amount of bandwidth.
Jul 18 '05 #2

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

Similar topics

3
by: Hitesh | last post by:
Hi, I am getting the response from another Website by using the HttpHandler in my current site. I am getting the page but all the images on that page are not appearing only placeholder are...
0
by: helldiversafe-news | last post by:
Hi all, I will use a apache soap service with an .net c# client and have a problem with an complex array: <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope...
3
by: Rahul Anand | last post by:
As per our requirements we have a web service which internally connects (Simple HTTP Post Request) to a remote server to initiate some work. We are calling the web service method asynchronously...
2
by: jl | last post by:
I have a J2ME cell phone application that via the AMS (Application Manager) delivers a status report to my server indicating whether the suite was successfully installed and identifying the reason...
4
by: AshishMishra16 | last post by:
HI friends, I am using the Flex to upload files to server. I m getting all the details about the file, but I m not able to upload it to Server. Here is the code i m using for both flex & for...
2
by: MDANH2002 | last post by:
Hi From VB.NET I want to simulate the POST request of the following HTML form <html> <title>HTTP Post Testing</title> <body> <form action=http://www.example.com/postdata ...
5
by: Dirk.Reimers | last post by:
Hi all, sorry for my dumb question: I use the following code: Dim request As WebRequest = HttpWebRequest.Create("http://" & ip & _ /TVBrowserTimerEvent?command=add") request.Credentials =...
1
by: MehtabKhan | last post by:
Any one who tell me what’s wrong with this code. When I pass values to pay pal by using www.sandbox.paypal.com/cgi-bin/webscr all the code are working well. The orders are generating accurately....
1
by: starter08 | last post by:
Hi, I have a C++ routine(client-side) which uploads an xml file to a web server by making a socket connection and sending all the post request through that socket. On the server side I have a cgi...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
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...
1
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...
1
isladogs
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
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.