私はここでもオンラインの他の場所を検索しましたが、私の考えは単純なエラーだとは思われません。基本的には、Python requests.POSTリクエストをリモートマシン上のJava RESTインターフェースに発行することによって、あるマシンから別のマシンにファイルを転送したいと考えています。 Java側は、次のようになります。Pythonの側PythonがPOSTをJava RESTインターフェイスに要求します。MultipartFileパラメータが存在しません。
@ApiOperation(value = "Binary file transfer", nickname = "Binary file transfer")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = HttpMessageInformationReturnDataBean.class),
@ApiResponse(code = 404, message = "Not Found")})
@RequestMapping(value = "/vm/{version}/uploadbinfile", method = RequestMethod.POST)
public String handleFileUpload(@RequestParam("binaryFile") MultipartFile file) {
if (!file.isEmpty())
{
try
{ ... the code that handles the transfer
、方法は次のようになります
def xfer_trm_binaries(self):
params = {"file": ('binaryFile',os.path.basename('TRMServer.jar')),
"folder": os.path.dirname(self.dest_temp_path),
"submit": "Submit"}
url = self.form_url("/vm/v1/uploadbinfile", self.trm_server_ip_address, self.vrm_server_port)
header=self.form_header(self.vrm_key)
header['Content-Type'] = 'multipart/file-data; boundary=randomboundarysequence'
header['enctype'] = "multipart/file-data"
print 'Send :' + url
binfile = self.local_jar_path+'TRMServer.jar'
with open(binfile, 'rb') as mfile:
try:
result = requests.post(url, headers=header,
data=params, files={'file': mfile}, verify=False)
except Exception:
が組み立てられますヘッダは、次のようになります
{'Content-Type': 'multipart/file-data; boundary=randomboundarysequence', 'Accept': 'application/json', 'Authorization': u'Bearer 8b2b6e53-9008-44b7-9d34-b5ecb9659250', 'enctype': 'multipart/file-data'}
要求は送信されますが、MultipartFileパラメータ 'binaryFile'に不満があるため、応答は常に400エラーです。
'{"timestamp":1488597880207,"status":400,"error":"Bad Request","exception":"org.springframework.web.bind.MissingServletRequestParameterException","message":"Required MultipartFile parameter \\'binaryFile\\' is not present","path":"/vm/v1/uploadbinfile"}'
リクエストのパラメーターとヘッダーの両方に「名前」値を追加しようとしましたが、常に400コードが返されます。そこにいる人は私が間違っていることを知っていますか?