-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.py
More file actions
53 lines (44 loc) · 1.53 KB
/
Application.py
File metadata and controls
53 lines (44 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
#########################################################################
# Author : Austin Dubina #
# Date : 3/6/2013 #
# Description: Small python script that querys PuppetLabs Inc. server #
# and returns the value of X-Answer header. #
# Reference : http://docs.python.org/2/library/httplib.html #
#########################################################################
import sys
import httplib
import urllib
class Main():
def __init__(self):
pass
# Establish a connection to PuppetLabs Inc. server
def openConnection(self, url, port):
self.conn = httplib.HTTPConnection(url, port)
# Request a response from server
def sendRequest(self, param):
try:
# Convert mapping object (param) to "percent-encoded" string
self.param = "/?%s" %urllib.urlencode({"email" : param})
self.conn.request("GET", self.param)
self.response = self.conn.getresponse()
except Exception as e:
print "Error: %s" % sys.exit(e)
#Print response values
def printResponse(self):
print "SERVER STATUS:", self.response.status, self.response.reason
print "X-ANSWER VALUE:", self.response.getheader('X-Answer')
print "LAST MODIFIED:", self.response.getheader('Last-modified')
print "RESPONSE:", self.response.read()
#Clean-up
def closeConnection(self):
try:
self.conn.close()
except Exception as e:
print "Error: %s" % sys.exit(e)
if __name__ == "__main__":
m = Main()
m.openConnection("updates.puppetlabs.com", 9091)
m.sendRequest("austin.dubina@gmail.com")
m.printResponse()
m.closeConnection()