Skip to content

Instantly share code, notes, and snippets.

@sheagcraig
Created March 10, 2015 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sheagcraig/dacdab9180c61086c8ab to your computer and use it in GitHub Desktop.
Save sheagcraig/dacdab9180c61086c8ab to your computer and use it in GitHub Desktop.
IconUpload Issue with JSS >9.64
#!/usr/bin/python
import urllib
import requests
# Obviously, our server name is swapped in for "ourjss".
# Policy ID 263 is Self Service policy installing Oracle Java 8 on our
# test server, running JSS v9.65
ICON_UPLOAD_URL_v965 = 'https://our965jss.org:8443/JSSResource/fileuploads/policies/id/263
# And this is URL specifies a policy on our production server, v9.6,
# which does the same thing.
ICON_UPLOAD_URL_v96 = 'https://our96JSS.org:8443/JSSResource/fileuploads/policies/id/1006
# User / pass obfuscated...
auth = ('<username>', '<password>')
icon = open('/Users/scraig/Desktop/OracleJava8.png', 'rb')
resource = {'name': icon}
# Attempt to FileUpload to 9.65:
response = requests.post(ICON_UPLOAD_URL_v965, auth=auth, verify=True,
files=resource)
icon.close()
print("Sent headers: %s" % response.request.headers)
print("Received headers: %s" % response.headers)
print("Response: %s" % response.status_code)
print("Response Content: %s" % response.text)
# Output:
# Sent headers: {'Content-Length': '12468', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.5.3 CPython/2.7.6 Darwin/14.1.0', 'Connection': 'keep-alive', 'Content-Type': 'multipart/form-data; boundary=a4880b0bac8d44b8984a4b8409f9a338', 'Authorization': 'Basic #REDACTED'}
# Received headers: {'content-length': '437', 'accept-ranges': 'bytes', 'vary': 'Accept-Charset, Accept-Encoding, Accept-Language, Accept', 'server': 'Restlet-Framework/2.1.7', 'cache-control': 'no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0', 'date': 'Wed, 04 Mar 2015 17:42:15 GMT', 'x-frame-options': 'SAMEORIGIN', 'content-type': 'text/html;charset=UTF-8'}
# Response: 409
# Response Content: <html>
# <head>
# <title>Status page</title>
# </head>
# <body style="font-family: sans-serif;">
# <p style="font-size: 1.2em;font-weight: bold;margin: 1em 0px;">Conflict</p>
# <p>API file upload exception:java.lang.NullPointerException</p>
# <p>You can get technical details <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.10">here</a>.<br>
# Please continue your visit at our <a href="/">home page</a>.
# </p>
# </body>
# </html>
# Attempt to FileUpload to 9.6:
auth = ('<username>', '<password>')
icon = open('/Users/scraig/Desktop/OracleJava8.png', 'rb')
resource = {'name': icon}
response = requests.post(ICON_UPLOAD_URL_v96, auth=auth, verify=True,
files=resource)
icon.close()
print("Sent headers: %s" % response.request.headers)
print("Received headers: %s" % response.headers)
print("Response: %s" % response.status_code)
print("Response Content: %s" % response.text)
# Output:
# Sent headers: {'Content-Length': '12468', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.5.3 CPython/2.7.6 Darwin/14.1.0', 'Connection': 'keep-alive', 'Content-Type': 'multipart/form-data; boundary=5884d9fdeee34d6ba2b78f37134b3e9b', 'Authorization': 'Basic #Redacted'}
# Received headers: {'transfer-encoding': 'chunked', 'accept-ranges': 'bytes', 'vary': 'Accept-Charset, Accept-Encoding, Accept-Language, Accept', 'server': 'Restlet-Framework/2.1.6', 'cache-control': 'no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0', 'date': 'Wed, 04 Mar 2015 17:42:15 GMT', 'x-frame-options': 'SAMEORIGIN', 'content-type': 'text/xml;charset=UTF-8'}
# Response: 201
# Response Content: <?xml version="1.0" encoding="UTF-8"?><policy><id>1006</id></policy>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment