使用Python请求和“ X-Frame-Options”上传文件:“ DENY”

时间:2018-08-02 20:47:32

标签: python-3.x python-requests

我正在尝试通过python请求库上传文件。这非常简单,我可以在其他应用程序中执行此操作。但是在一个安全应用程序中,我有一个如下所示的标题:

{'_content': b'{"fireeyeapis":{"@version":"v2.0.0","description":"Error
while trying to upload the file or parsing 
input","httpStatus":400,"message":"Error while trying to upload the file 
or parsing input"}}', '_content_consumed': True, '_next': None, 
'status_code': 400, 'headers': {'Date': 'Thu, 02 Aug 2018 20:26:58 GMT', 
'Server': 'Apache/2', 'X-Content-Type-Options': 'nosniff', 'Cache- 
Control': 'no-cache, no-store, must-revalidate, no-cache, no-store', 
'Pragma': 'no-cache', 'Expires': '0', 'Content-Type': 'application/json', 
'X-Frame-Options': 'DENY', 'X-XSS-Protection': '1; mode=block', 
'Connection': 'close', 'Transfer-Encoding': 'chunked'}, 'raw': 
 <urllib3.response.HTTPResponse object at 0x7f3cf71e2358>, 'url': 
'https://xxx.xx.xxx.xx/wsapis/v2.0.0/customioc/feed/add', 'encoding': 
 None, 'history': [], 'reason': 'Bad Request', 'cookies': 
<RequestsCookieJar[]>, 'elapsed': datetime.timedelta(0, 0, 26188), 
'request': <PreparedRequest [POST]>, 'connection': 
<requests.adapters.HTTPAdapter object at 0x7f3cfde60cc0>}

我总是有这个标题。我的上传方法就像:

    def create_custom_feed(self):

      headers = self.baseheaders
      headers.update({
        'Accept': 'application/json',
        'Content-Type': 'multipart/form-data'

      })

      payload = {
          'feedName': 'ip feed test',
          'feedType': 'ip',
          'feedAction': 'alert',
          'feedSource': 'thirdparty',
          'overwrite': 'true',
          'filename': "custom_feed"

    }

      url = self.base_url + "customioc/feed/add"
      submission = {'filename': open('custom_feed.txt', 'rb')}
      request = requests.post(url, verify=False, headers=headers, files=submission, data=payload)

      return request.json()

为什么“连接”:“关闭”?这里有什么问题?我认为我的代码正在运行,但是请求是否被服务器阻止?有关此问题的任何建议将不胜感激。

enter image description here

0 个答案:

没有答案