axiomhq / axiom-py

Official Python bindings for the Axiom API
https://axiom.co
MIT License
27 stars 19 forks source link

Client ingest api failing with UnicodeDecodeError on macos #117

Closed gitneran closed 2 months ago

gitneran commented 2 months ago

I did a pip install of axiom-py and was trying out the examples for the first time. I am getting the following error

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 369: invalid start byte

Below is the stack trace: Traceback (most recent call last): File "/Users/arur/code/axiom/ingest.py", line 14, in ingest("my-dataset") File "/Users/arur/code/axiom/ingest.py", line 10, in ingest res = client.ingest_events(dataset_name, [{"foo": "bar"}]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/axiom/client.py", line 223, in ingest_events return self.ingest( ^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/axiom/client.py", line 206, in ingest res = self.session.post(path, data=payload, headers=headers, params=params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/requests/sessions.py", line 637, in post return self.request("POST", url, data=data, json=json, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/requests_toolbelt/sessions.py", line 76, in request return super(BaseUrlSession, self).request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/requests/sessions.py", line 710, in send r = dispatch_hook("response", hooks, r, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/requests/hooks.py", line 30, in dispatch_hook _hook_data = hook(hook_data, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/axiom/client.py", line 161, in "response": lambda r, *args, **kwargs: raise_response_error(r) ^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/axiom/client.py", line 118, in raise_response_error print("##Response:", dump.decode("UTF-8"))

Code block I am trying to execute is ingest.py example

import axiom import rfc3339 from datetime import datetime,timedelta

def getAxiomClient(): return axiom.Client('', org_id='')

def ingest(dataset_name): client = getAxiomClient() res = client.ingest_events(dataset_name, [{"foo": "bar"}]) print("Ingested %d events with %d failures".format(res.ingested, res.failed))

if name == "main": ingest("my-dataset")

Can I get some help.

bahlo commented 2 months ago

Hi @gitneran, that is indeed not a good error. Fixed in #122. The underlying issue is probably a missing AXIOM_TOKEN env var.