TikTok-Api icon indicating copy to clipboard operation
TikTok-Api copied to clipboard

[BUG] - Empty userInfo for small accounts

Open ekorian opened this issue 2 years ago • 1 comments

Describe the bug

Certain accounts do not send userInfo, which triggers a KeyError when doing user(username)

{'extra': {'fatal_item_ids': [], 'logid': '20240308185549696ABBB4D8D733706647', 'now': 1709924160000}, 'log_pb': {'impr_id': '20240308185549696ABBB4D8D733706647'}, 'statusCode': 10221, 'status_code': 0, 'status_msg': '', 'userInfo': {}}

The buggy code

The user example with a small account name.

Expected behavior

Probably raise an EmptyResponse exception instead of a KeyError

Error Trace

Put the error trace below if there's any error thrown.

Traceback (most recent call last):
  File "/home/scripts/tiktok/tiktok_api.py", line 204, in <module>
    asyncio.run(scrap_tiktok_users())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/scripts/tiktok/tiktok_api.py", line 175, in scrap_tiktok_users
    users_data = [await user.info() for user in users]
  File "/home/scripts/tiktok/tiktok_api.py", line 175, in <listcomp>
    users_data = [await user.info() for user in users]
  File "/home/.local/lib/python3.10/site-packages/TikTokApi/api/user.py", line 87, in info
    self.__extract_from_data()
  File "/home/.local/lib/python3.10/site-packages/TikTokApi/api/user.py", line 204, in __extract_from_data
    data["userInfo"]["user"]["id"],
KeyError: 'user'

Desktop:

  • OS: Ubuntu 22
  • TikTokApi Version 6.2.1

ekorian avatar Mar 08 '24 19:03 ekorian

@mb21 noted that we might want to enforce a stricter separation between formats and output formats, which is not the case in this PR.

tarleb avatar Jun 15 '19 13:06 tarleb

@tarleb Yes, we probably should use the rule of thumb that a Format corresponds to a writer. That would mean there is markdown, but not markdown_mmd. There is HTML, but no HTML4, EPUB, slidy, etc. That makes sure that we produce syntactically valid output. (And people can always write different filters if they want different behaviours for different outputs.)

The exception to this rule is of course tex, which is still a format even though we have a latex and a context writer.

mb21 avatar Jun 15 '19 13:06 mb21

One thought I've sometimes had is that it would be cool if you could specify disjunctions of formats:

Format (LaTeX `or` ConTeXt)

or maybe even complements:

Format (not (LaTeX `or` ConTexT))

jgm avatar Jun 15 '19 16:06 jgm

I added experimental support for the IfFormat... constructors suggested in jgm/pandoc#547

tarleb avatar Jun 16 '19 15:06 tarleb

Note on why this is stalling (as far as I remember): it's not always clear what a "Format" really is, and I had trouble finding a good abstraction to capture this.

Format seems to be used as

  • a specific format, e.g. icml, rst;
  • a descriptor of a class of formats, e.g. tex, html, markdown;
  • a specific variant of a format variant, e.g. html5, epub2, latex, context.

Some of this can be handled by making Format a collection of formats, e.g. html being equivalent to [html4, html5]. I recall two issues with this:

(1) Sometimes a generic format has be be selected, e.g., 'html5' when html is specified as an input format. (2) the direction of a subset-relation is unclear. Is epub ⊂ html because EPUB is an HTML-based format, or is html ⊂ epub as raw HTML can occur in EPUB output.

All this isn't properly captured in the current PR, it has to be rewritten.

tarleb avatar Jan 14 '20 10:01 tarleb

Maybe the Format type has to be a partial order. That would help with 1 but not 2.

jgm avatar Jan 14 '20 16:01 jgm