2016-10-20 1 views
1

が、内部サーバーがあまりにもその同じ使ってポスターモジュールをエラーが発生しました:Pythonの:POSTリクエストのモジュールを使用してファイルをアップロードしようとするマルチパートエンコードファイル

import requests 
url = "abc.com/upload" 
querystring = {"ft":"1","fn":"filename"} 
payload = "" 
files={'file': open(r'Users/.../test.zip', 'rb')} 
headers_info = { 
    'content-type': "multipart/form-data; boundary=---12345", 
    'x-api-service-version': "1.0", 
    'connection': "Keep-Alive", 
    'authorization': "Basic XXXXXXX", 
    'x-file-format': "decrypted", 
    'cache-control': "no-cache", 
    } 

response = requests.post(url, data = payload , headers=headers_info , params=querystring , files=files) 

print response.status_code 
print response.text 

私はPOSTMANでAPIをテストした(Chromeの拡張機能へテスト残りのAPI)、それはうまく動作するように私は成功応答を取得し、ファイルがアップロードされている郵便配達員と思われる。 Pythonのショーのための

郵便配達コード:

import requests 
url = "abc.com/upload" 
querystring = {"ft":"1","fn":"filename"} 
payload = "" 
headers = { 
    'content-type': "multipart/form-data; boundary=---12345", 
    'accept-encoding': "gzip, deflate", 
    'x-api-service-version': "1.0", 
    'connection': "Keep-Alive", 
    'authorization': "Basic XXXXXXX", 
    'x-file-format': "decrypted", 
    'cache-control': "no-cache", 
    'postman-token': "XXXXXXX" 
    } 

response = requests.request("POST", url, data=payload, headers=headers, params=querystring) 

print(response.text) 

同じのための任意の提案ですか?私は明白な何かを欠いていますかあなたが共有できるポインタをありがとう!

+0

http://stackoverflow.com/questions/39738525/python-requests-how-to-add-content-を'authorization': "Basic XXXXXXX", 'postman-token': "XXXXXXX"ヘッダを追加しようとするかもしれませんが失敗した場合headers

response = requests.post(url, params=querystring , files=files) 

せずに要求を送信しようタイプ - マルチパート - フォーム - データ - リクエスト/ 39742334#39742334 –

答えて

0

'content-type': "multipart/form-data; boundary=---12345",と空のdataを指定する必要はありません。あなたは

+0

ありがとうございました.. – ksviswa

関連する問題