本文整理汇总了Python中threatconnect.RequestObject.RequestObject.set_content_type方法的典型用法代码示例。如果您正苦于以下问题:Python RequestObject.set_content_type方法的具体用法?Python RequestObject.set_content_type怎么用?Python RequestObject.set_content_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类threatconnect.RequestObject.RequestObject
的用法示例。
在下文中一共展示了RequestObject.set_content_type方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload
# 需要导入模块: from threatconnect.RequestObject import RequestObject [as 别名]
# 或者: from threatconnect.RequestObject.RequestObject import set_content_type [as 别名]
def upload(self, body):
""" upload document """
if self._resource_type == ResourceType.DOCUMENTS:
prop = self._resource_properties['document_upload']
elif self._resource_type == ResourceType.SIGNATURES:
prop = self._resource_properties['signature_upload']
else:
self._tc.tcl.error('Upload requested for wrong resource type.')
raise AttributeError(ErrorCodes.e10330.value)
ro = RequestObject()
ro.set_body(body)
ro.set_content_type('application/octet-stream')
ro.set_description('upload document for "{0}"'.format(self._name))
# determine whether the file contents exist using phase (not 100%)
if self.phase == 1:
ro.set_http_method(prop['http_method'])
else:
ro.set_http_method('PUT')
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_request_uri(prop['uri'].format(self._id))
ro.set_resource_pagination(prop['pagination'])
ro.set_resource_type(self._resource_type)
success_callback = lambda request, response: self.set_contents(request.body)
ro.set_success_callback(success_callback)
self._resource_container.add_commit_queue(self.id, ro)
示例2: download_request
# 需要导入模块: from threatconnect.RequestObject import RequestObject [as 别名]
# 或者: from threatconnect.RequestObject.RequestObject import set_content_type [as 别名]
def download_request(self):
""" """
# build request object
request_object = RequestObject(self._drd['name1'], self._drd['name2_method']())
request_object.set_content_type(self._drd['content_type'])
request_object.set_description(
self._drd['description'].format(self._drd['identifier_method']()))
request_object.set_http_method(self._drd['http_method'])
request_object.set_request_uri(
self._drd['request_uri_path'].format(self._drd['identifier_method']()))
request_object.set_owner_allowed(self._drd['owner_allowed'])
request_object.set_resource_pagination(self._drd['resource_pagination'])
request_object.set_resource_type(self._drd['resource_type'])
return request_object
示例3: upload
# 需要导入模块: from threatconnect.RequestObject import RequestObject [as 别名]
# 或者: from threatconnect.RequestObject.RequestObject import set_content_type [as 别名]
def upload(self, body):
""" upload batch job """
prop = self._resource_properties['batch_job_upload']
ro = RequestObject()
ro.set_body(body)
ro.set_content_type('application/octet-stream')
ro.set_description('upload batch job for "{0}"'.format(self._id))
ro.set_http_method(prop['http_method'])
ro.set_owner_allowed(prop['owner_allowed'])
ro.set_request_uri(prop['uri'].format(self._id))
ro.set_resource_pagination(prop['pagination'])
ro.set_resource_type(self._resource_type)
ro.empty_payload()
self._resource_container.add_commit_queue(self.id, ro)
示例4: RequestObject
# 需要导入模块: from threatconnect.RequestObject import RequestObject [as 别名]
# 或者: from threatconnect.RequestObject.RequestObject import set_content_type [as 别名]
from examples.working_init import *
from threatconnect.RequestObject import RequestObject
""" Toggle the Boolean to enable specific examples """
enable_example1 = False
enable_example2 = False
if enable_example1:
#
# build DOCUMENT request object
#
ro = RequestObject()
ro.set_http_method('POST')
body = {'name': 'Raw Upload Example', 'fileName': 'raw_example.txt'}
ro.set_body(json.dumps(body))
ro.set_content_type('application/json')
ro.set_owner('Example Community')
ro.set_owner_allowed(True)
ro.set_resource_pagination(False)
ro.set_request_uri('/v2/groups/documents')
# display request object parameters
print(ro)
#
# retrieve and display the results
#
results = tc.api_request(ro)
if results.headers['content-type'] == 'application/json':
data = results.json()
print(json.dumps(data, indent=4))