Skip to content

Instantly share code, notes, and snippets.

@pgorsira
Last active May 23, 2024 07:27
Show Gist options
  • Save pgorsira/ca978d06b90f9019bedb to your computer and use it in GitHub Desktop.
Save pgorsira/ca978d06b90f9019bedb to your computer and use it in GitHub Desktop.
Deploying to Artifactory with Python requests library
artifactory_url = 'artifactory.com' # your artifactory instance
artifactory_username = 'username' # your username
artifcatory_password = 'password' # your password
content_type = 'application/java-archive' # your content-type header
filename = 'file' # your file to upload (in current working directory)
url = artifactory_url + '/' + filename # where we want the file stored on artifactory
# checksums are useful for making sure the upload was successful
headers = {'content-type': content_type,
'X-Checksum-Md5': hashlib.md5(open(filename).read()).hexdigest(),
'X-Checksum-Sha1': hashlib.sha1(open(filename).read()).hexdigest()}
with open(filename, 'rb') as f:
r = requests.put(url,
auth=(artifactory_username,
artifactory_password),
data=f,
headers=headers)
# check for success
if r.status_code != 201:
print "Something went wrong"
else:
print r.json()['downloadUri'] # download url for this new artifact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment