lugia19 / elevenlabslib

Full python wrapper for the elevenlabs API.
MIT License
148 stars 27 forks source link

401 Client Error: Unauthorized for url #2

Closed JarodMica closed 1 year ago

JarodMica commented 1 year ago

I'm trying to run the example code provided in the readme and I'm getting this error:

401 Client Error: Unauthorized for url: https://api.elevenlabs.io/v1/voices
  File "C:\Users\jarod\Desktop\Code\Vivy\Test.py", line 11, in <module>
    voice = user.get_voices_by_name("Rachel")[0]  # This is a list because multiple voices can have the same name
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.elevenlabs.io/v1/voices

The code is simply:

import io
import json
import os
import elevenlabslib.helpers
from elevenlabslib import *

user = ElevenLabsUser("[my api key]")
voice = user.get_voices_by_name("Rachel")[0]  # This is a list because multiple voices can have the same name

voice.play_preview(playInBackground=False)
for sample in voice.get_samples():
    sample.play_audio(playInBackground=False)

voice.generate_and_play_audio("Test.", playInBackground=False)

for historyItem in user.get_history_items():
    if historyItem.text == "Test.":
        # The first items are the newest, so we can stop as soon as we find one.
        historyItem.delete()
        break

I don't have much experience working with Python and API's so I'm not sure why this error is occuring, I've tried to use a new API key, clear browser cookies, and log back in/out.

lugia19 commented 1 year ago

Yeah it's my bad, I shouldn't have put those goddamn brackets in the example, it's misleading. Just don't put the square brackets and you'll be fine.

JarodMica commented 1 year ago

Ah, solved. Thanks man!