[Zope] File Upload from Python

Zanotti Michele zanotti.m@apss.tn.it
Thu, 28 Feb 2002 11:11:17 +0100


Hi all,
Perhaps this is a Python question, not a Zope problem, but I hope someone
can help me.
I'm tryng to upload a file from PythonWin Ide (I have setted my Zope-test
permissions to anonymous). I obtain a 400 error with this page: "...Invalid
request id omitted...": but I don't understand where are my error(s). This
is my code:
>>> import httplib
>>> bd='--7d01ecf406a6'
>>> body=bd+'\r\ncontent-disposition: form-data;
name="id"\r\n\r\naloha\r\n'+bd+'\r\ncontent-disposition:   form-data;
name="title"\r\n\nxx\r\n'+bd+'\r\ncontent-disposition: form-data;
name="submit"\r\n\r\n add\r\n'
>>> body=body+bd+'\r\ncontent-disposition: form-data; name="file";
filename="prova.txt"\r\ncontent-type: text/plain\r\n\r\nprova\r\n'+bd+'--'
>>> conn = httplib.HTTPConnection("mypc:8080")
>>> conn.putrequest("POST", "/manage_addFile")
>>> conn.putheader('content-type','multipart/form-data; boundary='+bd)
>>> conn.putheader('content-length',str(lenb))
>>> conn.endheaders()
>>> conn.send(body)
>>> r=conn.getresponse()
>>> r.status
400
>>> print r.read()
...<P><STRONG>Invalid request</STRONG></P>
  The parameter, <em>id</em>, was omitted from the request.<p>...
Can anyone help me? Thanks and excuse if my errors are so trivial...
Michele
P.S. perhaps a better solution for batch upload is Curl or pyCurl, but I
find pycurl has too poor documentation for my level... Has anyone used it?