0

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

总的来说,这是我需要的,还有一些额外的。

除了 zipfile som 还需要其他信息,POST_DATA 看起来像这样:

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........................

海报 0.4 模块是否有可能(在你问之前,是的,我对 Python 还很陌生......)

亲切的问候,布赖恩·安德森

4

1 回答 1

4

海报具有基本和高级的多部分支持。
您可以尝试这样的事情(从海报文档修改):

# 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()
于 2009-06-25T08:04:24.093 回答