python - Administrating CQ5 via command line NOT using cURL or wget -


i'm trying write script administrating cq5 via command line not using curl or wget. when try upload package following error message:

{"success":false,"msg":"package file parameter missing"}

when using curl works fine. looked @ header , body curl sends , rebuilt both via python without success. curl doesn't seem send "file" parameter (or @ least didn't see it).

what file missing? how provide missing file?

i assume you're using ken reitz's excellent requests library http requests (if not, should be!)

most likely, problem requests doesn't add 'content-type' header multi-part uploads, , packmgr doesn't read multi-part bodies no 'content-type' header. so, while normal 'requests' post of multipart-encoded file go this:

url = 'http://localhost:4502/crx/packmgr/service/.json?cmd=upload' files = {'package': open('package.zip', 'rb')} r = requests.post(url, files=files) 

you instead have use longer form, setting explicit content-type:

url = 'http://localhost:4502/crx/packmgr/service/.json?cmd=upload' files = {'package': ('package.zip', open('package.zip', 'rb'), 'application/octet-stream')} r = requests.post(url, files=files) 

note 1 side-effect of doing way cannot stream file - entire package zip file read memory.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -