Calling an API

46 views
Skip to first unread message

Bastien Couzinier

unread,
Sep 6, 2023, 11:08:00 AM9/6/23
to xlSlim Support
Hi, I am trying to call a function from xlslim that's calling an API. The code perfectly runs on my machine. However when I get to actually call the API, it sounds like xlslim doesn't manage to log me in (although as said the code is working). Also, I checked the xlslim logs and there's no log error (given the function is running and then goes into the except). Could you please help me?

This is my code:

    baseUrl = 'xyz.com'
    tokenUrl = '/token'
    tokenPayload = {
    'username': 'user',
    'password': 'pw'
    }
    access_token=''
    url = f'{baseUrl}{tokenUrl}'
    try:
        resp = requests.post(url, json=tokenPayload)
        print(resp.status_code)
        if resp.status_code == 200:
            access_token = resp.json()['token']
    except Exception as e :
        return str(e)

xlSlim Dev

unread,
Sep 6, 2023, 11:48:19 AM9/6/23
to xlSlim Support
Hi,

I suggest adding some loggong to capture the error and debugging from there.

To add logging, import the logging module and get the logger:

import logging
LOG = logging.getLogger(__name__)

Then adjust your except Exception as e:

LOG.error(f"Failed to get token.", exc_info=True)

These changes will result in the error details being written to the xlSlim Python log file at %APPDATA%\Microsoft\AddIns\xlSlim\xlslim-python.log

Regards,
Russel
Message has been deleted
Message has been deleted

xlSlim Dev

unread,
Sep 6, 2023, 12:39:55 PM9/6/23
to xlSlim Support
Hi,

That is a failure within Python to establish a secure connection to the server you are connecting to. I am puzzled that it would work for you in an external Python process.

You could try update your certificates:
pip install –upgrade certifi

Regards,
Russel
On Wednesday, 6 September 2023 at 17:14:06 UTC+1 couzinie...@gmail.com wrote:
Hi, thanks for your reply. Here is the log file 

xlSlim Dev

unread,
Sep 7, 2023, 4:19:54 AM9/7/23
to xlSlim Support
Hi,

You should also check the site you are connecting at: https://www.ssllabs.com/ssltest/

I ran that data site through the ssl checks and it looks misconfigured.

All the best,
Russel

xlSlim Dev

unread,
Sep 7, 2023, 4:43:47 AM9/7/23
to xlSlim Support

Regards,
Russel

Bastien Couzinier

unread,
Sep 11, 2023, 10:50:31 AM9/11/23
to xlSlim Support
Thanks a lot for your help, setting verify = False fixed it as suggested in the stackoverflow link.

Thanks vm!
Reply all
Reply to author
Forward
0 new messages