Skip to content

Cannot create authorization token via python client #680

@marvinludersdorfer

Description

@marvinludersdorfer

Specifications

  • Client Version: 1.47.0
  • InfluxDB Version: 2.7.10
  • Python version: 3.13
  • Platform: Windows Server 2019 (64-bit)

Code sample to reproduce problem

I followed the Python client tutorial and adapted create_authorization to my needs:

from influxdb_client import Authorization, InfluxDBClient, Permission, PermissionResource
from influxdb_client.client.authorizations_api import AuthorizationsApi

org_id = "my-org-id"
bucket_id = "my-bucket-id"
description = "Write permission for device_name to bucket_name."

permissions = []
perm = PermissionResource(org_id=org_id, id=bucket_id, type="buckets")
permissions.append(Permission(action="write", resource=perm))

authorization = Authorization(org_id=org_id, permissions=permissions, description=description)
print(f"Authorization: {authorization}")

client = influxdb_client.InfluxDBClient(url=INFLUX_URL, token=INFLUX_TOKEN, org=INFLUX_ORG)
authorization_api = AuthorizationsApi(client)
device_token = authorization_api.create_authorization(authorization)

Expected behavior

The call to authorization_api.create_authorization(authorization) should return a newly created token.

Actual behavior

authorization_api.create_authorization(authorization) fails with return code 400
invalid json structure: json: cannot unmarshal object into Go struct field postAuthorizationRequest.orgID of type platform.ID

Additional info

Authorization: {'created_at': None,
'description': 'Write permission for device_name to bucket_name.',
'id': None,
'links': None,
'org': None,
'org_id': 'my-org-id',
'permissions': [{'action': 'write',
'resource': {'id': 'my-bucket-id',
'name': None,
'org': None,
'org_id': 'my-org-id',
'type': 'buckets'}}],
'status': 'active',
'token': None,
'updated_at': None,
'user': None,
'user_id': None}

Traceback (most recent call last):
File "C:\Users\EMnify\PycharmProjects\csv2influx\c_to_i\db\device.py", line 25, in create_authorization
return authorization_api.create_authorization(authorization)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "C:\Users\EMnify\PycharmProjects\csv2influx.venv\Lib\site-packages\influxdb_client\client\authorizations_api.py", line 30, in create_authorization
return self._authorizations_service.post_authorizations(authorization_post_request=authorization)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\EMnify\PycharmProjects\csv2influx.venv\Lib\site-packages\influxdb_client\service\authorizations_service.py", line 557, in post_authorizations
(data) = self.post_authorizations_with_http_info(authorization_post_request, **kwargs) # noqa: E501
File "C:\Users\EMnify\PycharmProjects\csv2influx.venv\Lib\site-packages\influxdb_client\service\authorizations_service.py", line 579, in post_authorizations_with_http_info
return self.api_client.call_api(
~~~~~~~~~~~~~~~~~~~~~~~~^
'/api/v2/authorizations', 'POST',
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<12 lines>...
collection_formats={},
^^^^^^^^^^^^^^^^^^^^^^
urlopen_kw=kwargs.get('urlopen_kw', None))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\EMnify\PycharmProjects\csv2influx.venv\Lib\site-packages\influxdb_client_sync\api_client.py", line 343, in call_api
return self.__call_api(resource_path, method,
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
path_params, query_params, header_params,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<2 lines>...
_return_http_data_only, collection_formats,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_preload_content, _request_timeout, urlopen_kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\EMnify\PycharmProjects\csv2influx.venv\Lib\site-packages\influxdb_client_sync\api_client.py", line 173, in __call_api
response_data = self.request(
method, url, query_params=query_params, headers=header_params,
post_params=post_params, body=body,
_preload_content=_preload_content,
_request_timeout=_request_timeout, **urlopen_kw)
File "C:\Users\EMnify\PycharmProjects\csv2influx.venv\Lib\site-packages\influxdb_client_sync\api_client.py", line 388, in request
return self.rest_client.POST(url,
~~~~~~~~~~~~~~~~~~~~~^^^^^
query_params=query_params,
^^^^^^^^^^^^^^^^^^^^^^^^^^
...<4 lines>...
body=body,
^^^^^^^^^^
**urlopen_kw)
^^^^^^^^^^^^^
File "C:\Users\EMnify\PycharmProjects\csv2influx.venv\Lib\site-packages\influxdb_client_sync\rest.py", line 311, in POST
return self.request("POST", url,
~~~~~~~~~~~~^^^^^^^^^^^^^
headers=headers,
^^^^^^^^^^^^^^^^
...<4 lines>...
body=body,
^^^^^^^^^^
**urlopen_kw)
^^^^^^^^^^^^^
File "C:\Users\EMnify\PycharmProjects\csv2influx.venv\Lib\site-packages\influxdb_client_sync\rest.py", line 261, in request
raise ApiException(http_resp=r)
influxdb_client.rest.ApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'X-Influxdb-Build': 'OSS', 'X-Influxdb-Version': 'v2.7.10', 'X-Platform-Error-Code': 'invalid', 'Date': 'Tue, 26 Nov 2024 14:45:22 GMT', 'Content-Length': '163'})
HTTP response body: {
"code": "invalid",
"message": "invalid json structure: json: cannot unmarshal object into Go struct field postAuthorizationRequest.orgID of type platform.ID"
}

From the debugger:

body = {'orgID': {'description': 'Write permission for device_name to bucket_name.', 'orgID': 'my-org-id', 'permissions': [{'action': 'write', 'resource': {'id': 'my-bucket-id', 'orgID': 'my-org-id', 'type': 'buckets'}}], 'status': 'active'}, 'status': 'active'}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy