Code Monkey home page Code Monkey logo

mygeotab-python's Introduction

MyGeotab

Build Status Documentation Code Coverage PyPI Version Python Versions License

A Python client for the MyGeotab SDK.

Features

  • Automatic serializing and deserializing of API call results
  • Clean, Pythonic API for querying data
  • Cross-platform and compatible with Python 3.7+
  • A myg command-line tool for interactively working with data in a terminal

Usage

It's very easy to get started once you've registered a MyGeotab database:

import mygeotab

client = mygeotab.API(username='[email protected]', password='mypass', database='MyDatabase')
client.authenticate()

devices = client.get('Device', name='%Test Dev%')

print(devices)

# [{'maxSecondsBetweenLogs': 200.0,
#   'activeTo': '2050-01-01',
#   'minAccidentSpeed': 3.0,
#   'ignoreDownloadsUntil': '1986-01-01',
#   'name': 'Test Device',
#   'idleMinutes': 3.0,
#   ......

You can also make calls asynchronously via asyncio:

import asyncio
import mygeotab

client = mygeotab.API(username='[email protected]', password='mypass', database='MyDatabase')
client.authenticate()

async def get_device():
  return await client.get_async('Device', name='%Test Dev%')

devices = loop.run_until_complete(get_device())
print(devices)

# [{'maxSecondsBetweenLogs': 200.0,
#   'activeTo': '2050-01-01',
#   'minAccidentSpeed': 3.0,
#   'ignoreDownloadsUntil': '1986-01-01',
#   'name': 'Test Device',
#   'idleMinutes': 3.0,
#   ......

Installation

To install the MyGeotab library and command line tool:

$ pip install mygeotab

or for the bleeding-edge version:

$ pip install git+https://github.com/geotab/mygeotab-python

Documentation

Read the docs at http://mygeotab-python.readthedocs.org

mygeotab-python's People

Contributors

aaront avatar aaront-geotab avatar dependabot[bot] avatar eyazrgeotab avatar matthewscanlan-geotab avatar mcallaghan-bsm avatar pieter-venter avatar pooriapoorsarvi avatar pyup-bot avatar sanyamguptageotab avatar softyy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mygeotab-python's Issues

Broken API Get "WorkTimeDetail"

Trying to get the "WorkTimeDetail" Entities and the get method is throwing an error:

import mygeotab

client = mygeotab.API(username=username, password=password, database=database)
client.authenticate()
print(client.call('GetVersion')) # 8.0.2441

data = client.get('WorkTimeDetail')

MyGeotabException: NotSupportedException
Cannot find bridge for Geotab.Checkmate.ObjectModel.WorkTimeDetail Path: $.Result.
image

Edit: Seeing this says "NotSupportedException". Will this be supported in the future?

Incorrect time types

In the request for trips, I get duration information (ex in the drivingDuration field) in a datetime.time format, which should be reserved for a time of the day. I would assume this would throw errors for duration more than 24 hours but I think the API happens to return only duration < 24.

It is really annoying since I can't process the data directly since no operation are supported between datetime.time objects. It would be great if duration could be parsed into a datetime.timedelta instead,.

Authentication with 'session_id' in the Credentials object raises 'ArgumentException'

When authenticating with a Credentials object that is given a session_id value and authenticating:

credentials = Credentials(username=..., database=..., server=..., session_id=...)
client = API.from_credentials(credentials)

The following error is returned:

{
    error: {
        code: -32000,
        data: {},
        errors: [
            {
                "message": "\"This method has been deprecated, and requires a custom code to be used. please use new methode 'ExtendSessionAsync' to extend your session.\"",
                "name": "'ArgumentException'",
            }
        ],
        message: "This method has been deprecated, and requires a custom code to be used. please use new methode 'ExtendSessionAsync' to extend your session.",
        name: "JSONRPCError",
    },
    id: -1,
    jsonrpc: "2.0",
    requestIndex: 0,
}

Details from GeoTab Community:
https://community.geotab.com/s/question/0D52J00009iEouYSAS/fail-to-authenticate-method-has-been-deprecated?language=en_US

mygeotab version: 0.8.8

Unable to authenticate

Hi,
I am getting ssl error during authentication. I have version 0.9.0, but same thing was happening with 0.8.8.
Host OS: Archlinux (up to date)
python: 3.12

Freshly created venv with mygeotab installed using pip.

I am not sure why certificate verify failed: unable to get local issuer certificate is happening.
When I try requests.get("https://my.geotab.com") everything works fine. So I think ssl works fine.

Maybe it's not relevant, but tests in CI are failing for quite some time and it also fails on authentication.

Traceback (most recent call last):
  File "/home/user/geotab_venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 467, in _make_request
    self._validate_conn(conn)
  File "/home/user/geotab_venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1099, in _validate_conn
    conn.connect()
  File "/home/user/geotab_venv/lib/python3.12/site-packages/urllib3/connection.py", line 653, in connect
    sock_and_verified = _ssl_wrap_socket_and_match_hostname(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/geotab_venv/lib/python3.12/site-packages/urllib3/connection.py", line 806, in _ssl_wrap_socket_and_match_hostname
    ssl_sock = ssl_wrap_socket(
               ^^^^^^^^^^^^^^^^
  File "/home/user/geotab_venv/lib/python3.12/site-packages/urllib3/util/ssl_.py", line 465, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/geotab_venv/lib/python3.12/site-packages/urllib3/util/ssl_.py", line 509, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/ssl.py", line 455, in wrap_socket
    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/ssl.py", line 1042, in _create
    self.do_handshake()
  File "/usr/lib/python3.12/ssl.py", line 1320, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/geotab_venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 793, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/home/user/geotab_venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 491, in _make_request
    raise new_e
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/user/geotab_venv/lib/python3.12/site-packages/requests/adapters.py", line 667, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/home/user/geotab_venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 847, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/home/user/geotab_venv/lib/python3.12/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='my.geotab.com', port=443): Max retries exceeded with url: /apiv1 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/devel/scripts/./geotab_receive_mime.py", line 10, in <module>
    client.authenticate()
  File "/home/user/geotab_venv/lib/python3.12/site-packages/mygeotab/api.py", line 259, in authenticate
    result = _query(
             ^^^^^^^
  File "/home/user/geotab_venv/lib/python3.12/site-packages/mygeotab/api.py", line 393, in _query
    response = session.post(
               ^^^^^^^^^^^^^
  File "/home/user/geotab_venv/lib/python3.12/site-packages/requests/sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/geotab_venv/lib/python3.12/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/geotab_venv/lib/python3.12/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/geotab_venv/lib/python3.12/site-packages/requests/adapters.py", line 698, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='my.geotab.com', port=443): Max retries exceeded with url: /apiv1 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)')))

Broken API Get "Driver"

I'm trying to export the Driver list using the API client, but am getting an InvaliCastException:

import mygeotab

client = mygeotab.API(username=username, password=password, database=database)
client.authenticate()

print(client.call('GetVersion')) # 8.0.2441
data = client.get('Driver')

MyGeotabException: InvalidCastException
Unable to cast object of type 'Geotab.Checkmate.Database.Bridge.UserBridge' to type 'Geotab.Database.IGetStore`1[Geotab.Checkmate.ObjectModel.Driver]'.
image

Broken API Get "WorkTime"

Trying to get the "WorkTime" Entities and the get method is throwing an error:

import mygeotab

client = mygeotab.API(username=username, password=password, database=database)
client.authenticate()
print(client.call('GetVersion')) # 8.0.2441

data = client.get('WorkTime')

AttributeError: 'str' object has no attribute 'keys'
image

Exception of type 'Geotab.Serialization.JsonSerializerException' was thrown.

I keep getting an exception when trying to query with the following parameters:

self.__client.call(
            "GetFeed",
            typeName="LogRecord",
            search={
                "deviceSearch": {
                    "id": device_id,
                },
                "fromDate": "2023-02-06 16:00:32 UTC",
                "toDate": "2023-02-06 16:10:32 UTC"
            },
            resultsLimit=10
        )

Here is the exception:

Exception of type 'Geotab.Serialization.JsonSerializerException' was thrown.

Using mygeotab version 0.8.8 and python version 3.9.13.

This was working like a day ago and isn't anymore. Any recent code changes to the API that could be causing this? Doing a Get to DeviceStatusInfo doesn't seem to be affected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.