----------------------------
CODE: SELECT ALL
<html><body>
   <form action="upload" method="post" enctype="multipart/form-data">
   filename: <input type="file" name="myFile" /><br />
   <input type="submit" />
   </form>
</body></html>
----------------------------
This works fine, however, sometimes, I need to run a separate python program
and tell it to upload another file instead of going through the html. I
think it it has something to do with urllib2, so this is what I tried:
---------------------------------
CODE: SELECT ALL
#!/usr/bin/python
import urllib
import urllib2
url = "http://localhost:5400/upload"
      
# this is POST data
values = {'type' : 'file', 'name' : "myfile.txt" }
   
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()
But I get this error
File "./test.py", line 13, in <module>
response = urllib2.urlopen(req)
File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.6/urllib2.py", line 397, in open
response = meth(req, response)
File "/usr/lib/python2.6/urllib2.py", line 510, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.6/urllib2.py", line 435, in error
return self._call_chain(*args)
File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
File "/usr/lib/python2.6/urllib2.py", line 518, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
I'm not exactly sure what is going on, any help would be appreciated.
-- 
View this message in context: http://old.nabble.com/using-python-to-call-cherrypost-post-tp31336238p31336238.html
Sent from the cherrypy-devel mailing list archive at Nabble.com.
http://www.google.com/search?q=urllib2+multipart+form-data
http://stackoverflow.com/questions/680305/using-multipartposthandler-to-
post-form-data-with-python
Robert Brewer
fuma...@aminus.org
    I already did a search on this before my post, and I did not find any
results that could help me solve the problem. It is probably due to my
understanding with the urllib module, and yes I read the documentation, and
I wrote the code base on my understanding. 
   Your search was no different from mine.  I posted a very specific
problem, I posted my code, and I just wanted to know what I did wrong. I
would really appreciated it if anyone can point out my mistakes, that would
be helpful for me. 
     Just as an advice, being brusk and arrogant only makes a person look
ignorant.
-- 
View this message in context: http://old.nabble.com/using-python-to-call-cherrypost-post-tp31336238p31344301.html