Netflix的Genie API要么采用JSON,要么采用multipart,在application/json
中有一部分request
,在application/octet-stream
中有任意数量的attachment
部分。你知道吗
请求使得简单的JSON POST非常简单:
requests.post(
url=self.host + self.endpoint,
json={
"version" : "1.0",
"user" : "genie",
"name" : "List * ... Directories bash job",
"description" : "Genie 3 Test Job",
"configs" : [ "/home/travis/build/Netflix/genie/genie-web/build/resources/test/com/netflix/genie/web/controllers/JobRestControllerIntegrationTests/job/config1" ],
"dependencies" : [ "/home/travis/build/Netflix/genie/genie-web/build/resources/test/com/netflix/genie/web/controllers/JobRestControllerIntegrationTests/job/dep1" ],
"setupFile" : "/home/travis/build/Netflix/genie/genie-web/build/resources/test/com/netflix/genie/web/controllers/JobRestControllerIntegrationTests/job/jobsetupfile",
"commandArgs" : "-c 'echo hello world'",
"clusterCriterias" : [ {
"tags" : [ "localhost" ]
} ],
"commandCriteria" : [ "bash" ],
},
)
命令是有限的,所以如果你有一个大的命令(查询)发送,你最好使用一个附件。你知道吗
对于请求,请求多部分也不是那么难:
requests.post(
url=self.host + self.endpoint,
json={
"version" : "1.0",
"user" : "genie",
"name" : "List * ... Directories bash job",
"description" : "Genie 3 Test Job",
"configs" : [ "/home/travis/build/Netflix/genie/genie-web/build/resources/test/com/netflix/genie/web/controllers/JobRestControllerIntegrationTests/job/config1" ],
"dependencies" : [ "/home/travis/build/Netflix/genie/genie-web/build/resources/test/com/netflix/genie/web/controllers/JobRestControllerIntegrationTests/job/dep1" ],
"setupFile" : "/home/travis/build/Netflix/genie/genie-web/build/resources/test/com/netflix/genie/web/controllers/JobRestControllerIntegrationTests/job/jobsetupfile",
"commandArgs" : "-c 'cat query.sql'",
"clusterCriterias" : [ {
"tags" : [ "localhost" ]
} ],
"commandCriteria" : [ "bash" ],
},
files={
"attachment": (
'query.sql',
'select count(1) from small_table;',
'application/octet-stream'
),
},
)
但是,如果files
存在,它将忽略json
,如果我将json
更改为data
,它将是一个窗体。我可以将JSON dict移到files
dict中,但它似乎没有作为JSON处理,现在我需要使用包来编码它?你知道吗
我这样问是因为requests
在参数和响应对象中处理json时,我怀疑它也会在某个地方处理多部分形式的json,否则我只会为json.dumps(...)
引入json
另外:
attachment
的部分,如果您需要多个附加文件,api将允许/期望这些部分。[在我的评论中,这可以通过将files
更改为列表名到文件对的列表来完成]。你知道吗Content-Disposition: form-data; name=request
和Content-Disposition: form-data; name=attachment
,而请求包似乎生成了Content-Disposition: form-data; name="attachment"
。你知道吗
“我可以将JSON dict移到文件dict中,但它似乎不能作为JSON处理”
“否则我带来的json只是为了json.dumps文件(…)”
“示例请求显示部件头的名称没有引号”
相关问题 更多 >
编程相关推荐