我遇到了 Alfresco 和 Python 的问题:我想直接用 Python 上传一个新文件。每次我尝试时都会收到 HTTP 500 错误而没有详细信息......
我首先尝试使用 CURL,以确保它正常工作,文件上传没有问题。
我使用了以下 curl 命令行:
url -X POST -uadmin:admin "http://localhost:8080/alfresco/service/api/upload" -F filedata=@/tmp/eeeeee.pdf -F siteid=test -F containerid=documentLibrary
在我的 Python 脚本中,我尝试了 PyCurl,现在是简单的 urllib。我认为问题来自文件作为参数给出的方式。
使用 PyCurl 的 Python 代码:
c = pycurl.Curl()
params = {'containerid': 'documentLibrary', 'siteid': 'test', 'filedata': open('/tmp/eeeeee.pdf', 'rb')}
c.setopt(c.URL, 'http://localhost:8080/alfresco/service/api/upload')
c.setopt(c.POST, 1)
c.setopt(c.POSTFIELDS, urllib.urlencode(params))
c.setopt(c.USERPWD, 'admin:admin')
c.perform()
此代码示例导致:
{
"code" : 500,
"name" : "Internal Error",
"description" : "An error inside the HTTP server which prevented it from fulfilling the request."
},
"message" : "04200017 Unexpected error occurred during upload of new content."
有人知道如何实现这一目标吗?
1 回答
您可以使用非常简单的库要求。
输出: