swappsco / toggl-python-api-client

Python-based REST client to interface with the Toggle API. Requires the 'requests' lib
GNU General Public License v2.0
15 stars 9 forks source link

Syntax error on import #2

Closed ianhinder closed 5 years ago

ianhinder commented 5 years ago

I have installed python-toggl from the distribution tarball, but am unable to import the package using the example given on the homepage.

wget https://files.pythonhosted.org/packages/18/c2/f9994ff2e7a7874e6d8f0daa2ba06f6cd20d5f0ef49bd142ffbedb240866/python-toggl-0.1.10.tar.gz
tar xfz python-toggl-0.1.10.tar.gz
cd python-toggl-0.1.10
python setup.py install --user
cat >togglapi.py <<EOF
from toggl-python-api-client.api_client import TogglClientApi

settings = {
    'token': 'xxx',
    'user_agent': 'your app name'
}
toggle_client = TogglClientApi(settings)

response = toggle_client.get_workspaces()
EOF
python togglapi.py

The output is

  File "togglapi.py", line 1
    from toggl-python-api-client.api_client import TogglClientApi
              ^
SyntaxError: invalid syntax

I am using Python 2.7.10 on Mac OS 10.14.2. The problem seems to be that the package is not called "toggl-python-api-client", but rather just "toggl". If I change it to "toggl", the package loads without problem.

cat >togglapi2.py <<EOF
from toggl.api_client import TogglClientApi

settings = {
    'token': 'xxx',
    'user_agent': 'your app name'
}
toggle_client = TogglClientApi(settings)

response = toggle_client.get_workspaces()
EOF
python togglapi2.py
Traceback (most recent call last):
  File "togglapi2.py", line 7, in <module>
    toggle_client = TogglClientApi(settings)
  File "/Users/h52229ih/toggltest/python-toggl-0.1.10/toggl/api_client.py", line 31, in __init__
    self.workspace_id = int(self.credentials['workspace_id'])
KeyError: 'workspace_id'

and gives the expected error about the workspace ID.

jlariza commented 5 years ago

Good day @ianhinder

Yes, the documentation is outdated. You should import the client using from toggl.api_client import TogglClientApi.

We will update the documentation asap. Thank you

ianhinder commented 5 years ago

Hi - the workspace id error is actually not expected; it looks like the example needs to also be updated for this. I needed to add workspace_id to the dict, which is not present in the example.