subzeroid / instagrapi

🔥 The fastest and powerful Python library for Instagram Private API 2024
https://hikerapi.com/p/bkXQlaVe
MIT License
4.38k stars 685 forks source link

[BUG] Input should be a valid string [type=string_type, input_value=123456789, input_type=int] #1693

Closed Tlaloc-Es closed 11 months ago

Tlaloc-Es commented 11 months ago

Try Instagrapi SaaS with a free trial https://hikerapi.com/p/5GBWznd3

Describe the bug The API returns the primary key (pk) as an int type, but Pydantic expects it to be of type str.

To Reproduce

Follow the guide to step session and the error start in cl.account_info()

Traceback

Traceback (most recent call last):
  File ".pyenv/versions/3.9.13/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File ".pyenv/versions/3.9.13/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/src/__main__.py", line 31, in <module>
    cli()
  File "/.venv/lib/python3.9/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/.venv/lib/python3.9/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/.venv/lib/python3.9/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/.venv/lib/python3.9/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/.venv/lib/python3.9/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/.venv/lib/python3.9/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/src/commands/comment/command.py", line 93, in comment_command
    user_login_handler = UserLoginHandler(ACCOUNT_USERNAME, ACCOUNT_PASSWORD)
  File "/src/integrations/__init__.py", line 22, in __init__
    self.login_user(username, password)
  File "/src/integrations/__init__.py", line 83, in login_user
    self._account_info = self.cl.account_info()
  File "/.venv/lib/python3.9/site-packages/instagrapi/mixins/account.py", line 59, in account_info
    return extract_account(result["user"])
  File "/.venv/lib/python3.9/site-packages/instagrapi/extractors.py", line 357, in extract_account
    return Account(**data)
  File "/.venv/lib/python3.9/site-packages/pydantic/main.py", line 150, in __init__
    __pydantic_self__.__pydantic_validator__.validate_python(data, self_instance=__pydantic_self__)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Account
pk
  Input should be a valid string [type=string_type, input_value=123456789, input_type=int]
    For further information visit https://errors.pydantic.dev/2.0.1/v/string_type

Expected behavior Login

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

Dev380 commented 11 months ago

I have the same issue - on github actions ubuntu

Tlaloc-Es commented 11 months ago

I guess is a pydantic version problem, I am triying with another versions but still don't find the correct one, with the 2.5.2, the problem is the use of the union with | in the types.

Tlaloc-Es commented 11 months ago

This issue is not the 2.0.0, but the latest one is in the 2.0.1. @Dev380