Python API Request in UiPath

Hello!

I have a Python script that sends an API request to a Docker connection.

Unfortunately I don’t know how to execute this API request in UiPath, can someone help me here?

The Python script looks like this:

from PIL import Image, ImageOps
from PIL import ImageDraw
import base64
from io import BytesIO
import requests
import json

filename = "File.txt

byteImg = Image.open(filename)
byteImg = ImageOps.exif_transpose(byteImg)

byteImgIO = BytesIO()
byteImg.save(byteImgIO, “JPEG”)
bio = byteImgIO.getvalue()
bio64 = base64.b64encode(bio)
sbio64 = bio64.decode(‘utf-8’)

url = ‘http://123
payload = ‘{ “preprocess”: “True”, “postprocess”: “Front”, “image” : “%s” }’ %sbio64
headers = {“accept”: “application/json”}
response = requests.post(url, data=payload, headers=headers)

get = requests.get(url, data=payload, headers=headers)

So now I need this API request in UiPath

Ich habe ein Python Script das einen API Request an eine Dockeranbindung sendet.

Leider weiß ich nicht, wie ich diesen API Request nun in UiPath durchführe, kann mir hier jemand helfen?

Das Python Script sieht so aus:

from PIL import Image, ImageOps
from PIL import ImageDraw
import base64
from io import BytesIO
import requests
import json

filename = “File.txt”

byteImg = Image.open(filename)
byteImg = ImageOps.exif_transpose(byteImg)

byteImgIO = BytesIO()
byteImg.save(byteImgIO, “JPEG”)
bio = byteImgIO.getvalue()
bio64 = base64.b64encode(bio)
sbio64 = bio64.decode(‘utf-8’)

url = ‘http://123
payload = ‘{ “preprocess”: “True”, “postprocess”: “Front”, “image” : “%s” }’ %sbio64
headers = {“accept”: “application/json”}
response = requests.post(url, data=payload, headers=headers)

get = requests.get(url, data=payload, headers=headers)

Jetzt brauche ich also diesen API Request in UiPath

@Beere_Plays

You can use python related activities …like python scope…load scripts and run script activities to execute your python code

Hope this helps

Cheers

Hey!

This isnt working for me, because the API Request has to be done over UiPath.

Or do you know you to input Variables from UiPath into the Python Script?

@Beere_Plays

Yes we can pass…please check the link for detailed description on how to pass arguments and invoke.Here is a glimpse

Cheers

Hey!

I dont realy understand how this is working, everytime i wanna start the RPA with Invoke Python code, it just dont realy starts.

It stays in the Screen of Doing nothing

@Beere_Plays

You need to do some prereqs not sure if you have done…Environment path variable need to have the python exe location…

If working directory is different then need to specify

you need to have only one version of python installed

Apart from this if not python what are your options

  1. Use invoke code and change the code from python to vb.net/c# and use it
  2. Http request I am little skepital on using base64 with http…if file attachments we can add as attachment sin http…can try that as well…for this better try building in postman…and it given you a curl…which can be pasted in UiPath import and get the parameters filled automatically

cheers