开发者

Getting isMultipartContent = false while using python poster library

开发者 https://www.devze.com 2023-01-07 07:59 出处:网络
I\'m using the python poster library to try to upload a form containing including an image to a servlet.Locally, it runs fine, but when I deploy to app engine, it doesn\'t recognize it as multipart co

I'm using the python poster library to try to upload a form containing including an image to a servlet. Locally, it runs fine, but when I deploy to app engine, it doesn't recognize it as multipart content.

ServletFileUpload.isMultipartContent(request) returns false

Here's how I'm using the poster library:

register_openers()开发者_如何学Python
datagen, headers = multipart_encode({"image": open(filename)})
request = urllib2.Request(url, datagen, headers)

The servlet checks to make sure it is Multipart, but it fails that check. What can I do to further debug?

Thanks, jean

*******update********* printing out the stack trace...here's what i get. It complains the content type header isnull

org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.(FileUploadBase.java:885) at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331) at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:349) at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)


If you're on Windows (or a pedant;-), open(filename) is the wrong way to open a binary file and might mess things up -- use open(filename, 'rb'). Apart from that, assuming of course that you continue with a urllib2.urlopen(request) which you've omitted, that your imports are correct, and that filename and url are properly set previously, then your code seems legit.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号