bookstack
bookstack copied to clipboard
TypeError thrown during generate_api_methods()
The code is as follows so far
api = bookstack.BookStack(base_url,
token_id=token_id,
token_secret=token_secret)
api.generate_api_methods()
the output
Traceback (most recent call last):
File "/home/keith/repo/release-automation-bookstack/release-checklist.py", line 13, in <module>
api.generate_api_methods()
File "/home/keith/repo/release-automation-bookstack/.venv/lib/python3.11/site-packages/bookstack/models.py", line 33, in generate_api_methods
method_name = self._create_method_name(method_info)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/keith/repo/release-automation-bookstack/.venv/lib/python3.11/site-packages/bookstack/models.py", line 70, in _create_method_name
'_'.join([method_info['method'], method_info['name']])
~~~~~~~~~~~^^^^^^^^^^
TypeError: string indices must be integers, not 'str'
BookStack v23.05.1
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Same issue, did you patch it @keithlee-co-uk ?
I received the same error with a wrongly configured API token. After setting "Access system API" for the tokens / users role. it works as expected.
You can verify it while being logged in with the relevant user and open: http://YOUR-IP/api/docs.json
Mmmhh interesting, i will try that. (I have actually re dev my own bookstack client because i was loosing to much time on this problem x) )
i tracked down the 1 character that wasted multiple hours. it's the extraneous / at the end of:
bookstack/models.py
API_PATH = 'api/docs.json/'
remove that character, API_PATH = 'api/docs.json', and all the problems wash away..
the problem was that when visiting .../api/docs.json/, the server would return a 301 redirect.
then, when following the redirect, underneath, python requests didn't re-apply the authorization at the new location, resulting in missing Authorization in the request headers, leading to the JSON response that says there's no valid credentials provided, resulting in this unhelpful TypeError. i'll submit a PR.