Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python上载Adobe AEM的问题-将curl命令转换为请求_Python_Aem - Fatal编程技术网

使用Python上载Adobe AEM的问题-将curl命令转换为请求

使用Python上载Adobe AEM的问题-将curl命令转换为请求,python,aem,Python,Aem,正在尝试将this curl命令转换为python curl-u admin:xxxxxxxx-F file=@“package.zip”-F name=“package.zip”-F force=true-F install=truehttp://host:port/crx/packmgr/service.jsp 尝试使用此选项,获得200个成功代码,但打印响应文本并查看服务器显示上载无效。有人能告诉我我做错了什么吗 import requests files = {

正在尝试将this curl命令转换为python

curl-u admin:xxxxxxxx-F file=@“package.zip”-F name=“package.zip”-F force=true-F install=truehttp://host:port/crx/packmgr/service.jsp

尝试使用此选项,获得200个成功代码,但打印响应文本并查看服务器显示上载无效。有人能告诉我我做错了什么吗

    import requests

    files = {
        'file': ('package.zip', open('package.zip', 'rb')),
        'name': (None, 'package.zip'),
        'force': (None, 'true'),
        'install': (None, 'true'),
    }

    response = requests.post('http://host:port/crx/packmgr/service.jsp', files=files, auth=('admin', 'xxxxxxxx'))


    print(response.headers)
    print(response.text)

我认为您缺少导入基本身份验证

from requests.auth import HTTPBasicAuth

response = requests.post('http://host:port/crx/packmgr/service.jsp', 
files=files, auth=HTTPBasicAuth('admin', '****'))
更新:

 import requests
 from requests.auth import HTTPBasicAuth
 url = 'http://localhost:4502/crx/packmgr/service.jsp'
 files = { 'file': ('mypackage.zip', 
 open('/Users/zospakir/Projects/mypackage.zip', 'rb'), 
 'application/zip')}
 data = dict(name='mypackage.zip', force='true',install='true')
 response = requests.post(url, files=files, data=data, auth=('admin', 
 '***'))
我明白了

问题在于如何解析源文件

   datafile=fullfile + "/" + filename
   url = "http://{}:{}/crx/packmgr/service.jsp".format(server,port)
   form_data = dict(
        file=(filename, open(datafile, 'rb'), 'application/zip', dict()),
        name=package.rstrip('.zip'),
        strict=True,
        force=(None, 'true'),
        install=(None, 'true')
   )
   resp = requests.post(url, auth=('admin', passwd), files=form_data)   
   if resp.status_code == 200:
       print(resp.headers)
       print(resp.text)
       print('Success!...  Response code 200')
       status = "Upload of " + package + " to " + url + "successful"
       package_location=pkg_group(resp.text)
       package_path=package_location + "/" + package
       #mailer.send(status,resp.text)
   else:
       print(resp.headers)
       print(resp.text)
       status='Upload of ' + package +  'Error detected!'
       sys.exit(1)

可能就是这样。我们将尽快测试它。谢谢按照建议修改了代码,但没有真正的区别。脚本连接并转储所有参数options@user796632,我已更新我的答案,您也缺少内容类型。