我是通过这个问题来到这里的:Send file using POST from a Python script
总的来说,这就是我需要的,外加一些额外的东西。
除了zipfile以外,还需要一些额外的信息,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........................poster 0.4模块有没有可能做到这一点(在你问之前,是的,我是Python的新手……)
致以亲切的问候,布莱恩·K·安德森
发布于 2009-06-25 08:04:24
Poster有基本的和高级的多部分支持。
你可以尝试这样的东西(从poster文档中修改):
# 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()https://stackoverflow.com/questions/1042451
复制相似问题