[Python] Issue with publishing python function as ontology function

Discussão em 'Python' iniciado por Stack, Setembro 26, 2024.

  1. Stack

    Stack Membro Participativo

    Now that palantir workshop supports using python repository as well along with typescript repository, I'm trying to create a python function which makes some api call and return a string value. The code works as expected in the live preview, but when I try to deploy to the ontology function and run it, it starts throwing error.

    @function
    def getProjectRID_Created_for_palantir_response(projectName: String) -> String:
    url = "https://domainName/compass/api/search/projects"
    headers = {
    'Content-type': 'application/json',
    'Authorization': 'Bearer XSSSS'
    }
    payload1 = {"pageSize":400,"query":"",}

    response1 = requests.post(url, headers=headers, json=payload1)

    if response1.status_code == 200:
    projects = response1.json()["values"]
    projects = json.dumps(projects)
    projects = json.loads(projects)

    for project in projects:
    if project['resource']['name'].lower() == projectName.lower():
    return project['resource']['rid']

    return "project not found"
    else:
    return f"failed to retrive projects:{response1.status_code}"


    below is the error what I get

    ConnectionError: HTTPSConnectionPool(host='domainName', port=443): Max retries exceeded with url: /compass/api/search/projects (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7fdff4543410>: Failed to resolve 'domainName' ([Errno -2] Name or service not known)")).
    Error Parameters: {}
    raise NameResolutionError(self.host, self, e) from e
    urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPSConnection object at 0x7fdff4543410>: Failed to resolve 'domainName' ([Errno -2] Name or service not known)


    I believe we have to create an egress policy and use it in the function, can anyone help me on how to use the egress policy tag here. I've also created the egress policy and imported to the repository but now sure how to use it in the function

    Continue reading...

Compartilhe esta Página