I have been trying to follow along the python walkthrough that is provided by influxDB to get familiar with how it works, and just by following the tutorial, I am getting errors, after following each step accordingly. All of the code is from them, yet I keep getting the same error:
>>> Request: 'POST https://us-east-1-1.aws.cloud2.influxdata.com/api/v2/write?org=PythonTesting&bucket=test1&precision=ns'
>>> Content-Type: text/plain
>>> Accept: application/json
>>> User-Agent: influxdb-client-python/1.37.0
>>> Body: b'census,location=Klamath bees=23i'
<<< Response: 401
<<< Date: Wed, 30 Aug 2023 17:15:22 GMT
<<< Content-Type: application/json; charset=utf-8
<<< Content-Length: 55
<<< Connection: keep-alive
<<< trace-id: a96c933eaca5845f
<<< trace-sampled: false
<<< x-platform-error-code: unauthorized
<<< Strict-Transport-Security: max-age=15724800; includeSubDomains
<<< X-Influxdb-Request-ID: 130ba81a98d7d837641571be3fabc194
<<< X-Influxdb-Build: Cloud
<<< Body: {"code":"unauthorized","message":"unauthorized access"}
Traceback (most recent call last):
File "C:\Users\user G\PycharmProjects\MEAfile_parsing\InfluxDB_testing.py", line 51, in <module>
client.write(database=database, record=point)
File "C:\Users\user\PycharmProjects\MEAfile_parsing\venv\lib\site-packages\influxdb_client_3\__init__.py", line 106, in write
raise e
File "C:\Users\user\PycharmProjects\MEAfile_parsing\venv\lib\site-packages\influxdb_client_3\__init__.py", line 104, in write
self._write_api.write(bucket=database, record=record, **kwargs)
File "C:\Users\user\PycharmProjects\MEAfile_parsing\venv\lib\site-packages\influxdb_client\client\write_api.py", line 378, in write
results = list(map(write_payload, payloads.items()))
File "C:\Users\user\PycharmProjects\MEAfile_parsing\venv\lib\site-packages\influxdb_client\client\write_api.py", line 376, in write_payload
return self._post_write(_async_req, bucket, org, final_string, payload[0])
File "C:\Users\user\PycharmProjects\MEAfile_parsing\venv\lib\site-packages\influxdb_client\client\write_api.py", line 509, in _post_write
return self._write_service.post_write(org=org, bucket=bucket, body=body, precision=precision,
File "C:\Users\user\PycharmProjects\MEAfile_parsing\venv\lib\site-packages\influxdb_client\service\write_service.py", line 60, in post_write
(data) = self.post_write_with_http_info(org, bucket, body, **kwargs) # noqa: E501
File "C:\Users\user\PycharmProjects\MEAfile_parsing\venv\lib\site-packages\influxdb_client\service\write_service.py", line 90, in post_write_with_http_info
return self.api_client.call_api(
File "C:\Users\user\PycharmProjects\MEAfile_parsing\venv\lib\site-packages\influxdb_client\_sync\api_client.py", line 343, in call_api
return self.__call_api(resource_path, method,
File "C:\Users\user\PycharmProjects\MEAfile_parsing\venv\lib\site-packages\influxdb_client\_sync\api_client.py", line 173, in __call_api
response_data = self.request(
File "C:\Users\user\PycharmProjects\MEAfile_parsing\venv\lib\site-packages\influxdb_client\_sync\api_client.py", line 388, in request
return self.rest_client.POST(url,
File "C:\Users\user\PycharmProjects\MEAfile_parsing\venv\lib\site-packages\influxdb_client\_sync\rest.py", line 311, in POST
return self.request("POST", url,
File "C:\Users\user\PycharmProjects\MEAfile_parsing\venv\lib\site-packages\influxdb_client\_sync\rest.py", line 261, in request
raise ApiException(http_resp=r)
influxdb_client.rest.ApiException: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Date': 'Wed, 30 Aug 2023 17:15:22 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '55', 'Connection': 'keep-alive', 'trace-id': 'a96c933eaca5845f', 'trace-sampled': 'false', 'x-platform-error-code': 'unauthorized', 'Strict-Transport-Security': 'max-age=15724800; includeSubDomains', 'X-Influxdb-Request-ID': '130ba81a98d7d837641571be3fabc194', 'X-Influxdb-Build': 'Cloud'})
HTTP response body: {"code":"unauthorized","message":"unauthorized access"}
Process finished with exit code 1
I have tried resetting the access token environment variable multiple times with full access to everything, but nothing changed. all of the variables such as host and org were set by the tutorial and configured by it for my particular set up. if you wish to see the tutorial here it requires a sign up here: https://cloud2.influxdata.com/signup
yes I also have all of the dependencies installed. here is the code with some edits to the links and variables for privacy reasons:
import os, time
from influxdb_client_3 import InfluxDBClient3, Point
token = os.environ.get("INFLUXDB_TOKEN") # this I set in as an environmental variable from an all #access token that is given via the tutorial
org = "PythonTesting"
host = "myhost" # host link is given to me and provided by aws
client = InfluxDBClient3(host=host, token=token, org=org, debug=True)
database="test1"
data = {
"point1": {
"location": "Klamath",
"species": "bees",
"count": 23,
},
"point2": {
"location": "Portland",
"species": "ants",
"count": 30,
},
"point3": {
"location": "Klamath",
"species": "bees",
"count": 28,
},
"point4": {
"location": "Portland",
"species": "ants",
"count": 32,
},
"point5": {
"location": "Klamath",
"species": "bees",
"count": 29,
},
"point6": {
"location": "Portland",
"species": "ants",
"count": 40,
},
}
for key in data:
point = (
Point("census")
.tag("location", data[key]["location"])
.field(data[key]["species"], data[key]["count"])
)
client.write(database=database, record=point)
time.sleep(1) # separate points by 1 second
print("Complete. Return to the InfluxDB UI.")
again you can follow along the tutorial and see that this is from influxdb's instructional intro. This is supposed to be a five minute set up so I don't know why this is happening. I see there is many other stack overflow pages with similar questions, none of which are fully answered or even acknowledged. I hope that this can be solved so others can resolve the same issue.