pycurl PostFields 选项用法
我正在尝试使用 pycurl 将文件上传到 Processmaker。 app、self.usr 和 doc 是字符串。 file 是 django 文件字段对象。我目前只是传递该对象。我相当确定我只是将错误的对象/类型/事物传递给 ATTACH_FILE 字段。
工作的 php POSTFIELDS 定义如下所示:
$params = array (
'ATTACH_FILE' => '@/home/test.txt',
'APPLICATION' => $resultCase->caseId,
'INDEX' => 1,
'USR_UID' => $oRandomUser->guid,
'DOC_UID' => '3154812864d55a6e017ff65089604572',
'APP_DOC_TYPE' => 'INPUT',
'TITLE' => "Initial document".date("Y-m-d H:i:s"),
'COMMENT' => "this document was uploaded by the system"
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
当前损坏的 python:
c = pycurl.Curl()
data = [
('ATTACH_FILE', (pycurl.READFUNCTION, file.read)),
('APPLICATION', app),
('INDEX' , 1),
('USR_UID', self.usr),
('DOC_UID', doc),
('APP_DOC_TYPE', 'INPUT')
]
post = urllib.urlencode(data)
print post
url = "http://192.168.51.155/sysworkflow/en/green/services/upload"
c.setopt(pycurl.URL, url)
c.setopt(pycurl.VERBOSE, 1)
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, post)
c.perform()
c.close()
有什么想法吗?
I'm trying to use pycurl to upload a file to Processmaker. app, self.usr, and doc are strings. file is a django file field object. I'm currently just passing the object. I'm fairly sure I'm just passing the incorrect object/type/thing to the ATTACH_FILE field.
The working php POSTFIELDS definition looks like this:
$params = array (
'ATTACH_FILE' => '@/home/test.txt',
'APPLICATION' => $resultCase->caseId,
'INDEX' => 1,
'USR_UID' => $oRandomUser->guid,
'DOC_UID' => '3154812864d55a6e017ff65089604572',
'APP_DOC_TYPE' => 'INPUT',
'TITLE' => "Initial document".date("Y-m-d H:i:s"),
'COMMENT' => "this document was uploaded by the system"
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
And the currently broken python:
c = pycurl.Curl()
data = [
('ATTACH_FILE', (pycurl.READFUNCTION, file.read)),
('APPLICATION', app),
('INDEX' , 1),
('USR_UID', self.usr),
('DOC_UID', doc),
('APP_DOC_TYPE', 'INPUT')
]
post = urllib.urlencode(data)
print post
url = "http://192.168.51.155/sysworkflow/en/green/services/upload"
c.setopt(pycurl.URL, url)
c.setopt(pycurl.VERBOSE, 1)
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, post)
c.perform()
c.close()
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决我自己问题的方法。这是我所做的,使用位于此处的海报: http://atlee.ca/software/poster/ 我做了以下事情:
比 pycurl 更容易使用!我第一次尝试的问题是 POSTFIELDS 无法接受文件(没有一些争论)并且使用 HTTPPOST 选项可以处理文件,但很难同时处理文件数据和字段数据。
I found a way to solve my own issue. Here is what I did, using poster located here: http://atlee.ca/software/poster/ I did the following:
Much easier to use than pycurl! The problem with my first attempt was that POSTFIELDS can't accept files (without some wrangling) and using an HTTPPOST option would work with the files but was difficult to get working with both file data and field data.