質問

この質問でここに来ました: PythonスクリプトからPOSTを使用してファイルを送信

そして、概して、私が必要とするものに加えて、いくつかの追加物です。

zipファイルのほかに、追加情報が必要であり、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にはかなり新しいです...)

よろしく、 ブライアンK.アンデルセン

役に立ちましたか?

解決

ポスターには、基本的および高度なマルチパートサポートがあります。
次のようなものを試すことができます(ポスターのドキュメントから変更):

# 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()
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top