My format is correct as per normal Python requests module rule, but still I am not able to upload a file to AEM using Python.
How do we convert the following
curl -u admin:admin -F file=@"C:\sample\samplepackage.zip" -F name="samplepackage" -F force=true -F install=false http://localhost:4502/crx/packmgr/service.jsp
to its Python equivalent??
This is what I used and it does not upload but gives me a 200 response code and says format is wrong
**************************************************************************************************************
#!/path-to-python-2.7.5/bin/python
import os
import requests
api_url = 'http://host:port/crx/packmgr/service.jsp'
os.chdir("/my/folder"); #change directory to where file.zip is located, and this I tested with subprocess listing and path is right
# Set up a session
session = requests.Session()
filehandle=open("file.zip",'rb')
payload = {}
payload['file'] = ('file.zip',filehandle)
payload['force'] = 'true'
payload['install'] = 'false'
payload['name'] = 'zipfile'
print payload
r = session.post(api_url, data=payload, files=payload, auth=('admin', '*******'))
print r.text
**************************************************************************************************************
What I get as output is the following which makes me think if something is missing in the requests module that AEM wants???
***********************
<crx version="1.6.2" user="admin" workspace="crx.default">
<request>
<param name="force" value="true"/>
<param name="install" value="false"/>
<param name="file" value="file.zip"/>
<param name="name" value="zipfile"/>
</request>
<response>
<data>
+------------+-----------------------------------------+
| Arguments | Comment |
+------------+-----------------------------------------+
½ | cmd=help | print this help |
+------------+-----------------------------------------+
| cmd=ls | print a list of all packages |
+------------+-----------------------------------------+
| cmd=rm | remove a package |
| name | package name |
| [group] | group name (optional) |
+------------+-----------------------------------------+
| cmd=build | build a package |
| name | package name |
| [group] | group name (optional) |
+------------+-----------------------------------------+
| cmd=inst | install a package |
| name | package name |
| [strict] | true to fail on error |
| [group] | group name (optional) |
+------------+-----------------------------------------+
| cmd=uninst| uninstall a package |
| name | package name |
| [group] | group name (optional) |
+------------+-----------------------------------------+
| GET | download a package |
| | (content-disposition header contains |
| | the correct filename) |
| [cmd=get] | optional |
| name | package name |
| [group] | group name (optional) |
+------------+-----------------------------------------+
| POST | upload a new package |
| file | package to upload |
| [name] | optional name |
| [strict] | true to fail on install error |
| [install] | automatically install package if 'true' |
+------------+-----------------------------------------+
</data>
<status code="200">ok</status>
</response>
</crx>