ALERT! The community will be read-only starting on April 19, 8am Pacific as the migration begins. Read more for important details.
ALERT! The community will be read-only starting on April 19, 8am Pacific as the migration begins.Read more for important details.
Cadet 3rd Class
Cadet 3rd Class
360 views

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.

 

0 Likes
0 Replies
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.