Skip to content

create_bucket trigger IndexError: list index out of range #403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Bugazelle opened this issue Feb 13, 2022 · 3 comments · Fixed by #408
Closed

create_bucket trigger IndexError: list index out of range #403

Bugazelle opened this issue Feb 13, 2022 · 3 comments · Fixed by #408

Comments

@Bugazelle
Copy link

Bugazelle commented Feb 13, 2022

Steps to reproduce:
run any of the following code, the error triggered
client.buckets_api().create_bucket(bucket_name='my-bycket')
client.buckets_api().create_bucket(bucket_name='my-bycket', org='my-org')

only working if:
client.buckets_api().create_bucket(bucket_name='my-bycket', org='the org id here')
client.buckets_api().create_bucket(bucket_name='my-bycket', org_id='the org id here')

But, seems there is no way from this python client to get the org id

Actual behavior:
The error triggered as bellow

Traceback (most recent call last):
  File "/Users/mr.banana/Bugazelle/export-csv-to-influx/src/ExportCsvToInflux/influx_object.py", line 161, in <module>
    influxdb.create_influx_db_if_not_exists(bucket='ken')
  File "/Users/mr.banana/Bugazelle/export-csv-to-influx/src/ExportCsvToInflux/influx_object.py", line 119, in create_influx_db_if_not_exists
    client.buckets_api().create_bucket(bucket_name=bucket)
  File "/Users/mr.banana/PythonVM3/lib/python3.8/site-packages/influxdb_client-1.25.0-py3.8.egg/influxdb_client/client/bucket_api.py", line 55, in create_bucket
    org_id=get_org_query_param(org=(org_id if org is None else org),
  File "/Users/mr.banana/PythonVM3/lib/python3.8/site-packages/influxdb_client-1.25.0-py3.8.egg/influxdb_client/client/util/helpers.py", line 35, in get_org_query_param
    return client.organizations_api().find_organizations(org=_org)[0].id
IndexError: list index out of range

Specifications:

  • Client Version: 1.25.0
  • InfluxDB Version: 2.1.1
  • Platform: MacOS
@bednar
Copy link
Contributor

bednar commented Feb 14, 2022

Hi @Bugazelle,

thanks for using our client.

client.buckets_api().create_bucket(bucket_name='my-bycket') client.buckets_api().create_bucket(bucket_name='my-bycket', org='my-org')

Traceback (most recent call last):
  File "/Users/mr.banana/Bugazelle/export-csv-to-influx/src/ExportCsvToInflux/influx_object.py", line 161, in <module>
    influxdb.create_influx_db_if_not_exists(bucket='ken')
  File "/Users/mr.banana/Bugazelle/export-csv-to-influx/src/ExportCsvToInflux/influx_object.py", line 119, in create_influx_db_if_not_exists
    client.buckets_api().create_bucket(bucket_name=bucket)
  File "/Users/mr.banana/PythonVM3/lib/python3.8/site-packages/influxdb_client-1.25.0-py3.8.egg/influxdb_client/client/bucket_api.py", line 55, in create_bucket
    org_id=get_org_query_param(org=(org_id if org is None else org),
  File "/Users/mr.banana/PythonVM3/lib/python3.8/site-packages/influxdb_client-1.25.0-py3.8.egg/influxdb_client/client/util/helpers.py", line 35, in get_org_query_param
    return client.organizations_api().find_organizations(org=_org)[0].id
IndexError: list index out of range

It looks like that your organization name isn't correct.

Can you check presents the organization by:

orgs = client.organizations_api().find_organizations(org='my-org')
print(orgs)

?

Regards

@bednar bednar added the question Further information is requested label Feb 14, 2022
@Bugazelle
Copy link
Author

Bugazelle commented Feb 15, 2022

Hi @bednar ,

thank you for the suppport

I have find the root cause: because of my token is the read/write api token for all bucket.
If I used all access api token, everything works fine

when using the read/write api token, I got the following result:

orgs = client.organizations_api().find_organizations(org='my-org')
print(orgs)
# []

I think it is still the issue we need to fix

@bednar
Copy link
Contributor

bednar commented Feb 15, 2022

Traceback (most recent call last):
File "/Users/mr.banana/Bugazelle/export-csv-to-influx/src/ExportCsvToInflux/influx_object.py", line 161, in
influxdb.create_influx_db_if_not_exists(bucket='ken')
File "/Users/mr.banana/Bugazelle/export-csv-to-influx/src/ExportCsvToInflux/influx_object.py", line 119, in create_influx_db_if_not_exists
client.buckets_api().create_bucket(bucket_name=bucket)
File "/Users/mr.banana/PythonVM3/lib/python3.8/site-packages/influxdb_client-1.25.0-py3.8.egg/influxdb_client/client/bucket_api.py", line 55, in create_bucket
org_id=get_org_query_param(org=(org_id if org is None else org),
File "/Users/mr.banana/PythonVM3/lib/python3.8/site-packages/influxdb_client-1.25.0-py3.8.egg/influxdb_client/client/util/helpers.py", line 35, in get_org_query_param
return client.organizations_api().find_organizations(org=_org)[0].id
IndexError: list index out of range

I think that we have to improve the

def get_org_query_param(org, client, required_id=False):
to use better exception when we are not able to find the organization by name.

@bednar bednar added state: confirmed and removed question Further information is requested labels Feb 16, 2022
@bednar bednar added this to the 1.25.0 milestone Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants