Python 2.6- UPLOAD ZIP 파일 - 포스터 0.4
-
22-07-2019 - |
문제
나는이 질문을 통해 여기에 왔습니다.Python 스크립트에서 게시물을 사용하여 파일을 보냅니다
그리고 대체로 그것은 내가 필요로하는 것입니다.
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 모듈에서 어떻게 든 가능합니까 (그리고 당신이 물어보기 전에, 나는 파이썬을 처음 접 했어요 ...)
친절한, Brian K. Andersen
해결책
포스터에는 기본 및 고급 멀티 파트 지원이 있습니다.
이와 같은 것을 시도 할 수 있습니다 (포스터 문서에서 수정) :
# 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()
제휴하지 않습니다 StackOverflow