【发布时间】:2015-05-21 09:31:40
【问题描述】:
我在使用 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."
有人知道如何实现吗?
【问题讨论】:
-
请edit 您的问题并包括您使用的
curl命令。还请包括失败的 Python 代码。 Alfresco 日志是否包含错误消息? -
谢谢,已编辑!日志中没有错误消息,只是: ::1 - - [21/May/2015:10:08:49 +0200] "POST /alfresco/service/api/upload HTTP/1.1" 500 6580
-
这看起来像是访问日志中的一行。查看
catalina.out日志文件。
标签: python curl upload alfresco