我写了一个上传CSAR的测试, 问题是我收到415回复而不是200回复。
Postman to python code:
导入请求
url =“https://x.x.x.x:port/path”
payload =“------ WebKitFormBoundary7MA4YWxkTrZu0gW \ r \ nContent-Disposition:form-data; name = \”csar \“; filename = \”csar \“\ r \ nConContent-Type:false \ r \ ñ\ r \ n \ r \ n ------ WebKitFormBoundary7MA4YWxkTrZu0gW--” headers = { 'content-type':“multipart / form-data; boundary = ---- WebKitFormBoundary7MA4YWxkTrZu0gW”, 'X-AUTH-TOKEN': “eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJOQ1NPIiwiaWF0IjoxNTI4MDEyNDc0LCJleHAiOjE1MjgwOTg4NzQsImp0aSI6IjA4MTJlNDM3LTk3MDEtNDM4NS1iNGIzLTc5YzNhNWU3YTQyYyIsInVzZXJOYW1lIjoibmNzbyIsInRlbmFudCI6IlRlc3QiLCJyb2xlcyI6WyJOQ1NPQWRtaW4iXX0 = .s8CuE0d4bwKQxd6jYhAM5Slx5mYmZNQCf / SGytPxzOQ =” }
response = requests.request(“POST”,url,data = payload,headers = headers)
我的测试: def csar_upload():
file = "/csar.csar"
upload_csar.csar_upload( file)
API实施:
def upload_csar(self, files):
f = FileSystem.get_binary_file(files)
file_parts = {"csar": f}
print file_parts
response = restcall.upload_call(file_parts)
if response == True:
return True, response
else:
return False, response
致电:
class restcalls(object):
@classmethod
def upload_csar(cls, files):
method = 'POST'
url = system_ip() + '/path'
headers = headers_path.someheader
response = requests.post(method, url, headers, files=files)
return response
我收到回复:415媒体不受支持。
标题正常,文件正常。 也许是界限。是否有任何方法可以编写它,以便它可以在我的python测试中工作?
谢谢。