posthog icon indicating copy to clipboard operation
posthog copied to clipboard

TypeError on /decide endpoint: a bytes-like object is required, not 'str'

Open sentry[bot] opened this issue 3 years ago • 3 comments

Sentry Issue: POSTHOG-60E

TypeError: a bytes-like object is required, not 'str'
(2 additional frame(s) were not displayed)
...
  File "django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "posthog/api/decide.py", line 100, in get_decide
    data = load_data_from_request(request)
  File "posthog/utils.py", line 512, in load_data_from_request
    return decompress(data, compression)
  File "posthog/utils.py", line 446, in decompress
    data = gzip.decompress(data)
  File "gzip.py", line 547, in decompress
    with GzipFile(fileobj=io.BytesIO(data)) as f:

sentry[bot] avatar May 23 '22 06:05 sentry[bot]

I believe this is caused by this refactor: https://github.com/PostHog/posthog/commit/e98a20b4a3658236f3c13de917e950060f28199c / https://github.com/PostHog/posthog/pull/9794

cc @pauldambra

Note that the tests mock out gzip completely - I believe calling gzip in most cases will fail.

We now also assume a default compression of gzip - which is incorrect for how posthog-js operates right now. The previous default of base64 encoding is still correct.

macobo avatar May 23 '22 06:05 macobo

Looking at this again, this seems to be a case where (vanilla) data is correctly encoded as base64 but something in our surrogatepass-dealing base64 encoding methods causes this to fail when re-encoding the string as utf-16.

The gzip-related errors are noise added by the complexity added in the linked PRs.

macobo avatar May 23 '22 07:05 macobo

This issue hasn't seen activity in two years! If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in two weeks.

posthog-bot avatar May 22 '24 07:05 posthog-bot

This issue was closed due to lack of activity. Feel free to reopen if it's still relevant.

posthog-bot avatar Jun 05 '24 07:06 posthog-bot