cityofaustin / knackpy

A Python client for interacting with Knack applications
https://cityofaustin.github.io/knackpy/docs/user-guide/
Other
39 stars 17 forks source link

SSLError when using URL Slug for dedicated server #117

Open elrezad opened 5 months ago

elrezad commented 5 months ago

Hi team, thank you for this software.

We've recently moved our Knack apps to a dedicated server at apps.mycompany.com. The endpoint for the api should be api.apps.mycompany.com, but when I try to connect it throws an error:

requests.exceptions.SSLError: HTTPSConnectionPool(host='api.apps.mycompany.com-api.knack.com', port=443): Max retries exceeded with url: /v1/applications/60df87fxxxxxxxxxxxxxxxx (Caused by SSLError(CertificateError("hostname 'api.apps.mycompany.com-api.knack.com' doesn't match '*.knack.com'")))

I've contacted Knack's support, but any help would be much appreciated.

Thanks and best regards

elrezad commented 5 months ago

Hi Team, here are Knack's comments:

The Knackpy appears to have some sections hardcoded to use the public API endpoint (api.knack.com), however, in these sections, you will need to replace with your endpoint. One example, and there may be other sections (as a 3rd party library, we aren't very familiar or in a position to repair):

the Knackpy codebase and the API URL is hardcoded:https://github.com/cityofaustin/knackpy/blob/cf236649f9347218b2f29e7babd2f531cb39fc6e/knackpy/api.py#L21

It would appear then this is where you would need to make the update as wel

l as other areas as well.

I have edited (my apoligies if there's a better way of pointing to the code) api.py>def _url

`return (

f"https://{slug}-api.knack.com/v1{route}"

    f"https://{slug}/v1{route}" # slug must be the full url
    if slug
    else f"https://api.knack.com/v1{route}"
)`

using as slug the full url of the private domain api.apps.mycompany.com

With this change, I can connect to Knack with knackpy.App(), but I get the following error when using get("object_1"):

File ".venv/lib/python3.11/site-packages/knackpy/api.py", line 172, in _get_paginated_records res = _request( [...] requests.exceptions.ConnectionError: HTTPSConnectionPool(host='MYCOMPANY', port=443): Max retries exceeded with url: /v1/objects/object_10/records/?page=1&rows_per_page=1000 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f09d25ffd90>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

elrezad commented 5 months ago

Hi Team, any help here would be greatly appreciated