使用 python 海报库时获取 isMultipartContent = false
我正在使用 python 海报库尝试将包含图像的表单上传到 servlet。在本地,它运行良好,但是当我部署到应用程序引擎时,它不会将其识别为多部分内容。
ServletFileUpload.isMultipartContent(request) 返回 false
以下是我使用海报库的方式:
register_openers()
datagen, headers = multipart_encode({"image": open(filename)})
request = urllib2.Request(url, datagen, headers)
servlet 检查以确保它是 Multipart,但检查失败。我可以做什么来进一步调试?
谢谢, 吉恩
*****更新************ 打印出堆栈跟踪...这就是我得到的。它抱怨内容类型标头为null
org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException:请求不包含多部分/表单数据或多部分/混合流,内容类型标头为空 在 org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.(FileUploadBase.java:885) 在 org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331) 在 org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:349) 在 org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
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()
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是 Windows(或学究;-),
open(filename)
是打开二进制文件的错误方法,并且可能会搞砸 - 使用open(filename, ' rb')
。除此之外,当然假设您继续使用您省略的 urllib2.urlopen(request) ,您的import
是正确的,并且filename
和url
之前已正确设置,那么您的代码看起来是合法的。If you're on Windows (or a pedant;-),
open(filename)
is the wrong way to open a binary file and might mess things up -- useopen(filename, 'rb')
. Apart from that, assuming of course that you continue with aurllib2.urlopen(request)
which you've omitted, that yourimport
s are correct, and thatfilename
andurl
are properly set previously, then your code seems legit.