Python Akamai Content Control Utility Example
This python example script will invalidate all URLs for the given CP Code via the Akamai Content Control Utility API.
########################################
import httplib
d = dict(
USERNAME = USERNAME,
PASSWORD = PASSWORD,
EMAIL = EMAIL,
CPCODE = CPCODE
)
soap_message = """<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<purgeRequest xmlns="http://ccuapi.akamai.com/purge">
<name xsi:type="xsd:string">%(USERNAME)s</name>
<pwd xsi:type="xsd:string">%(PASSWORD)s</pwd>
<network xsi:type="xsd:string">ff</network>
<opt soapenc:arrayType="xsd:string[3]" xsi:type="soapenc:Array">
<item xsi:type="xsd:string">email-notification=%(EMAIL)s</item>
<item xsi:type="xsd:string">type=cpcode</item>
<item xsi:type="xsd:string" />
</opt>
<uri soapenc:arrayType="xsd:string[1]" xsi:type="soapenc:Array">
<item xsi:type="xsd:string">%(CPCODE)s</item>
</uri>
</purgeRequest>
</soap:Body>
</soap:Envelope>
""" % d
print soap_message
# construct and send the header
webservice = httplib.HTTP("ccuapi.akamai.com")
webservice.putrequest("POST", "/soap/servlet/soap/purge")
webservice.putheader("Host", "ccuapi.akamai.com")
webservice.putheader("User-Agent", "Python post")
webservice.putheader("Content-type", "text/xml; charset=\"UTF-8\"")
webservice.putheader("Content-length", "%d" % len(soap_message))
webservice.putheader("SOAPAction", "http://ccuapi.akamai.com/purge#purgeRequest")
webservice.endheaders()
webservice.send(soap_message)
# get the response
statuscode, statusmessage, headers = webservice.getreply()
print "Response: ", statuscode, statusmessage
print "Headers: \n", headers
result = webservice.getfile().read()
print result
