Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - byUsername #550

Closed
alzeric opened this issue Apr 1, 2021 · 2 comments
Closed

[BUG] - byUsername #550

alzeric opened this issue Apr 1, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@alzeric
Copy link

alzeric commented Apr 1, 2021

Describe the bug

byUsername throws a list index out of range error

The buggy code

api = TikTokApi.get_instance()
userData = api.byUsername('belleryanooo52', count=10)

Expected behavior

A clear and concise description of what you expected to happen.

Return user

Error Trace (if any)

Put the error trace below if there's any error thrown.
(This is the tail end of it... appears to be printing out the entire html in the console)

              // Check that service workers are supported
              if ('serviceWorker' in navigator) {
              // Use the window load event to keep the page load performance
              window.addEventListener('load', function() {
                navigator.serviceWorker.register('/sw.js').catch(function() {
                  console.log('Service worker registration failed');
                });
              });
            }
            </script></html>
Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\TikTokApi\tiktok.py", line 1209, in get_user
    j_raw = t.split(
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Desktop (please complete the following information):

  • OS: Windows 10 Pro
  • TikTokApi Version: 3.9.4

Additional context

Add any other context about the problem here.

@alzeric alzeric added the bug Something isn't working label Apr 1, 2021
@alzeric alzeric changed the title [BUG] - Your Error Here [BUG] - byUsername Apr 1, 2021
@alzeric
Copy link
Author

alzeric commented Apr 1, 2021

Couple things

1.) They've added a nonce attribute to all <script and <link tags (gets assigned in the <head tag
2.) secUid has been moved to the jsonldList object

This quick fix will get things back up and running...
get_user function

        t = r.text

        try:
            nonce_start = '<head nonce="'
            nonce_end = '">'
            nonce = t.split(nonce_start)[1].split(nonce_end)[0]
            j_raw = t.split(
                '<script id="__NEXT_DATA__" type="application/json" nonce="%s" crossorigin="anonymous">' % nonce
            )[1].split("</script>")[0]```

@MuffinFox
Copy link
Contributor

fix for all functions parsing script tag content: MuffinFox@57fefee

@alzeric alzeric closed this as completed Apr 1, 2021
davidteather added a commit that referenced this issue Apr 1, 2021
davidteather added a commit that referenced this issue Apr 1, 2021
IshShamari pushed a commit to AmpMe/TikTok-Api that referenced this issue Nov 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants