mixpanel / mixpanel-utils

Other
85 stars 62 forks source link

Fix HTTP request logic for /jql endpoint #45

Closed mherrman closed 2 years ago

mherrman commented 2 years ago

Running a script using the query_jql function from python 3.10.0 returns an error:

Traceback (most recent call last):
  File "/Users/****/Desktop/donna_export.py", line 14, in <module>
    results = mputils.query_jql(query)
  File "/Users/****/.pyenv/versions/3.10.0/lib/python3.10/site-packages/mixpanel_utils/__init__.py", line 1009, in query_jql
    response = self.request(
  File "/Users/****/.pyenv/versions/3.10.0/lib/python3.10/site-packages/mixpanel_utils/__init__.py", line 247, in request
    data = params["data"]
KeyError: 'data'

The same script seems to return results fine when using python 3.9.1.

Script:

from mixpanel_utils import MixpanelUtils

mputils = MixpanelUtils('API_Secret', token='Token')

query = '''function main() {
  return Events({
    from_date: '2022-02-01',
    to_date:   '2022-02-18'
  })
  .groupBy(["name"], mixpanel.reducer.count());
}'''

results = mputils.query_jql(query)
print(results)
argenisf commented 2 years ago

@mherrman @jaredmixpanel I don't think this is actually related to the version of python. I just wan into the same error, and when reviewing the source of the library, the request function expects a "data" key in the params.

I guess that is because all the ingestion APIs have that "data" key. The SDK has a check for /engage so a quick fix likely is to also check for "jql" there: https://github.com/mixpanel/mixpanel-utils/blob/master/init.py#L242

jaredmixpanel commented 2 years ago

@mherrman @argenisf thanks for the report, this should be fixed in v2.2.5. let me know if run into anything else.