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

KeyError: 'data' #55

Open
RABIDYOTE opened this issue Apr 28, 2024 · 4 comments
Open

KeyError: 'data' #55

RABIDYOTE opened this issue Apr 28, 2024 · 4 comments

Comments

@RABIDYOTE
Copy link

Whenever I try to use the script with a file, it throws me this message which doesn't entirely seem to line up with any status code in particular. I've tried both using a file with multiple lines and one with just one line. I've also tried the recommended Session ID as well as my own, and making sure the aid value is set correctly.

Traceback (most recent call last):
  File "C:\Users\jprig\Downloads\tiktok-voice-main\main.py", line 158, in <module>
    main()
  File "C:\Users\jprig\Downloads\tiktok-voice-main\main.py", line 126, in main
    tts(args.session, text_speaker, item, f'{batch_dir}{i}.mp3', False)
  File "C:\Users\jprig\Downloads\tiktok-voice-main\main.py", line 31, in tts
    vstr = [r.json()["data"]["v_str"]][0]
            ~~~~~~~~^^^^^^^^
KeyError: 'data'

I also tried to use it with just a text argument, but it outputs this instead:

Traceback (most recent call last):
  File "C:\Users\jprig\Downloads\tiktok-voice-main\main.py", line 158, in <module>
    main()
  File "C:\Users\jprig\Downloads\tiktok-voice-main\main.py", line 138, in main
    tts(args.session, text_speaker, req_text, filename, play)
  File "C:\Users\jprig\Downloads\tiktok-voice-main\main.py", line 31, in tts
    vstr = [r.json()["data"]["v_str"]][0]
            ~~~~~~~~^^^^^^^^
KeyError: 'data'

I'm unfortunately not very code-savvy, so I'm a bit confused on what's going on and how I can rectify it.

@bdwyer1911
Copy link

I'm getting the same error. Were you able to find a fix?

@jvatsal21
Copy link

Also getting the same issue

@jvatsal21
Copy link

Alright, I got the fix. First change this line:
if r.json()["message"] == "Couldn't load speech. Try again.":
to:
if r.json()["message"] == "Couldn’t load speech. Try again.":
This is just a minor error in apostrophe comparison; however, the main issue is that the code thinks your sessionID is incorrect. The way I fixed this is by changing this line:
API_BASE_URL = f"https://api16-normal-v6.tiktokv.com/media/api/text/speech/invoke/"
to:
API_BASE_URL = f"https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/".
This should do the job!

abirabedinkhan added a commit to abirabedinkhan/tiktok-voice that referenced this issue May 14, 2024
Session timeout was fixed since the incorrect base endpoint was used. As mentioned in issue oscie57#55
@darkzbaron
Copy link

I changed the URL to API_BASE_URL = f"https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/" with no sucess, any help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants