Skip to main content

Issue Authenticating with Session in Python (attempt 2)

TuckerBA-1087
Original Poster

I tried posting this last week but it's stuck in Pending Review, so I've taken a screenshot to post it again. I suspect the post got flagged for review because I mention the authenticate() method and it probably needs to be reviewed to make sure I didn't accidentally expose credentials. It's been in review for a week though so I'm going ahead and trying a repost to see if this works.

 

Repost 

Hopefully this works.

 

Thanks,

Tucker

Join the conversation

You need to be logged in to reply to this post and participate in the Geotab Community discussions.

Top Answers

After working with Tucker today we were able to determine that including the server to the first section of code in his original request is the solution:

 

imageIt can also be noted that to avoid authenticating multiple times, using a try/except where the except retrieves the session id from the credentials object can be utilized if a script is being run multiple times:

imageJarod S.

5 Replies

Hi Tucker,

 

Thanks for reaching out to the Geotab Community!

 

It looks like you did everything right so far. However, I just added the server (example: my23.geotab.com) which allowed for successful authentication:

 

image 

Also, if you're using Google Colab, I would recommend importing and using getpass. If you structure the sessionId variable similarly to the screenshot above with getpass, it will prompt you to type it in and it won't be stored in the notebook for an added security measure.

 

All the best,

Jarod

TuckerBA-1087
Original Poster

Hey Jarod,

 

Thanks for the reply. I'm going to reply to this twice, this one will be about the authenticate method you showed in your post. I tried that and I'm still getting an error. Here's my exact code with credentials removed:

 

image 

And this is the error I get:

 

image 

Do you see anything I'm doing wrong? I'm using Python 3.7 if that matters.

Hey Tucker,

 

I'll reach out to you via a message on this platform to further recreate your issue and will post the solution here once we've figured it out.

 

Thanks,

Jarod

TuckerBA-1087
Original Poster

Replying to give a quick update. I was on mygeotab 0.8.5 for the python wrapper and that was causing the issue with authenticating with a session_id and password (it was working with just a password on that version). Once I updated, I was able to authenticate with a password and session_id, but the session_id wasn't working so it was still having to re-authenticate with the password every time the script was run.

 

Jarod and I had a call and I noticed that the most recent version doesn't have the commit by aaront in the repository that was made on April 10th. That fix addresses the issue with the dbUnavailableException and allows the script to run, but even copying in his changes to my api.py file in my mygeotab package, I still fail the initial request and have to re-authenticate with the password. This results in the authenticate() method being called every time the function is run (which in this case is 3 times a minute). Obviously I don't want to have to do that, and I'd rather re-use the session_id. Jarod is looking into it further but if anyone else has any ideas let me know.

After working with Tucker today we were able to determine that including the server to the first section of code in his original request is the solution:

 

imageIt can also be noted that to avoid authenticating multiple times, using a try/except where the except retrieves the session id from the credentials object can be utilized if a script is being run multiple times:

imageJarod S.

Still have questions?