Connecting to an Instance Using Python
This section describes how to connect to a GeminiDB Influx instance using the Python programming language.
Prerequisites
The Python client of InfluxDB has been installed.
Example Code for Accessing an Instance Using a Non-SSL Connection
from influxdb import InfluxDBClient # There will be security risks if the username and password used for authentication are directly written into code. Store the username and password in ciphertext in the configuration file or environment variables. # In this example, the username and password are stored in the environment variables. Before running this example, set environment variables EXAMPLE_USERNAME_ENV and EXAMPLE_PASSWORD_ENV as needed. username = os.getenv('EXAMPLE_USERNAME_ENV') password = os.getenv('EXAMPLE_PASSWORD_ENV') client = InfluxDBClient(host=IP, port=****, username=username, password=password, ssl=False) client.get_list_database()
Replace host and port with the actual values.
Example Code for Accessing an Instance Using an SSL Connection
from influxdb import InfluxDBClient # There will be security risks if the username and password used for authentication are directly written into code. Store the username and password in ciphertext in the configuration file or environment variables. # In this example, the username and password are stored in the environment variables. Before running this example, set environment variables EXAMPLE_USERNAME_ENV and EXAMPLE_PASSWORD_ENV as needed. username = os.getenv('EXAMPLE_USERNAME_ENV') password = os.getenv('EXAMPLE_PASSWORD_ENV') client = InfluxDBClient(host=IP, port=****, username=username, password=password, ssl=True) client.get_list_database()
- Replace host and port with the actual values.
- The value of ssl must be True.
- If SSL is not set or is set to False, the following error information is displayed:
InfluxDBClientError: 400: Client sent an HTTP request to an HTTPS server.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot