首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python 2.6 -上传zip文件- Poster 0.4

Python 2.6 -上传zip文件- Poster 0.4
EN

Stack Overflow用户
提问于 2009-06-25 06:43:29
回答 1查看 1.9K关注 0票数 0

我是通过这个问题来到这里的:Send file using POST from a Python script

总的来说,这就是我需要的,外加一些额外的东西。

除了zipfile以外,还需要一些额外的信息,POST_DATA看起来像这样:

代码语言:javascript
复制
POSTDATA =-----------------------------293432744627532
Content-Disposition: form-data; name="categoryID"

1
-----------------------------293432744627532
Content-Disposition: form-data; name="cID"

-3
-----------------------------293432744627532
Content-Disposition: form-data; name="FileType"

zip
-----------------------------293432744627532
Content-Disposition: form-data; name="name"

Kylie Minogue
-----------------------------293432744627532
Content-Disposition: form-data; name="file1"; filename="At the Beach x8-8283.zip"
Content-Type: application/x-zip-compressed

PK........................

poster 0.4模块有没有可能做到这一点(在你问之前,是的,我是Python的新手……)

致以亲切的问候,布莱恩·K·安德森

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-06-25 08:04:24

Poster有基本的和高级的多部分支持。

你可以尝试这样的东西(从poster文档中修改):

代码语言:javascript
复制
# test_client.py
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import urllib2

# Register the streaming http handlers with urllib2
register_openers()

# headers contains the necessary Content-Type and Content-Length
# datagen is a generator object that yields the encoded parameters
datagen, headers = multipart_encode({
    'categoryID' : 1,
    'cID'        : -3,
    'FileType'   : 'zip',
    'name'       : 'Kylie Minogue',
    'file1'      : open('At the Beach x8-8283.zip')
})

# Create the Request object
request = urllib2.Request("http://localhost:5000/upload_data", datagen, headers)

# Actually do the request, and get the response
print urllib2.urlopen(request).read()
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1042451

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档