Skip to main content

Hi, 

I am trying to automate the import of bots into the productive control room using python. But I always get the error 'Can\'t read the uploaded file part'. Manually it is working. My code is the following:

 

headers = { "content-type":"multipart/form-data", "X-Authorization", "token that I generated"}

with open('C:\\...\\TESTAPI.zip', 'rb') as f: 

payload = MultipartEncoder(fields={'upload': ('TESTAPI.zip', f, 'application/zip'),

'actionIfExisting': 'OVERWRITE', 'publicWorkspace': 'False'})

     url = "https://" + control-room-server + "/v2/blm/import"

     response = requests.request("POST", url, headers=headers, data=payload,

verify=path\\zertificate.cer")

Any suggestions? With Postman this import API is also not working.

 

Thanks in advance,

Henriette

Hi @Henriette Franz​ ,

 

Here is an article from the Official Website on Bot Lifecycle Management.

I hope you find it resourceful.

 

Kind Regards,

Ashwin A.K


Hi @Henriette Franz​ , probably you have solved it already, but as I recently had the same issue, I am posting here what I've found:

 

Apparently, when sending multipart content with requests in Python (i am using requests 2.28.1 with python 3.10), you don't need to specify the 'content-type' header. I had tried everything until I found some post mencioning this, so I deleted the content-type from my header, and as simply as that, my code started working.

 

#export_name = 'yourexport.zip'

importFile = open(export_name,'rb')

headers = {

  'Accept': 'application/json',

  'X-Authorization': token

}

data={

  'actionIfExisting': 'OVERWRITE',

  'publicWorkspace': 'false'

}

files=p

  ('upload',(export_name,importFile,'application/zip'))

]

  

r = requests.post(endpoint + '/v2/blm/import', data=data, files=files,headers=headers, verify=False)

 

 

Hope it helps, if not to you, to others like me that could'nt find the solution here.

 

Regards.

 

Gonzalo.


@gonzalomh91 thankyou very much, I had similar issues but now it's working.


Reply