Uploading attachment - results in Bad request (400)

Hi,

I am trying to upload a simple text file to a manual test with test ID 30014 using Rest API in python. But every time i try to call the Requests.post it result in HTTP error 400 Bad request. I have tried several things but nothing seems to work. I have no idea where i am going wrong. below is the code i am using.

in python:

param={"name":"test.txt","owner_test":{"id":"30014","type":"test"}}

files = ('text.txt', open('C:/Test/test.txt','rb').read(), 'text/plain')

result = requests.post(url,

                       data=param,

                       files = {'file': files},

                       headers={"Content-Type":"multipart/form-data;boundary=a1b2c3d4","Accept":"applicatio/json"},

                       cookies = self.__cookies, verify = self.__cert)

self._oLogger.info("request is %s with the status code: %s ", self.Status[result.status_code],result.status_code)

print result.text

Response is:

INFO: request is Bad request with the status code: 400

{"error_code":"platform.web_application","correlation_id":"3z9yl0k9vqj69hyzy3k71wmoq","description":"HTTP 400 Bad Request","description_translated":"HTTP 400 Bad Request","properties":null,"business_error":false}

 

If anyone have any idea how i can resolve this, it will be of great help.