Мой код работал до тех пор, пока я не решил переместить свои учетные данные Google Api в мою среду Docker. Я использую Flask в качестве основы веб-сервера.
Это мои настройки:
DOCKER:
docker-compose-dev.yml
environment:
- FLASK_ENV=development
- APP_SETTINGS=project.config.DevelopmentConfig
- GOOGLE_APPLICATION_CREDENTIALS=/usr/src/app/project/api/resources/youtube/urls/project-84a0ef4dcd33.json
FLASK:
config.py
class DevelopmentConfig(BaseConfig):
CREDENTIALS = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS')
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
video.py
from project.config import DevelopmentConfig
CREDENTIALS = DevelopmentConfig.CREDENTIALS
YOUTUBE_API_SERVICE_NAME = DevelopmentConfig.YOUTUBE_API_SERVICE_NAME
YOUTUBE_API_VERSION = DevelopmentConfig.YOUTUBE_API_VERSION
def youtube_id(track_name):
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, credentials=CREDENTIALS,
developerKey=None)
search_response = youtube.search().list(
q=track_name,
part="id,snippet",
).execute()
videos = []
videos_ids = []
channels = []
playlists = []
for search_result in search_response.get("items", []):
if search_result["id"]["kind"] == "youtube#video":
videos.append("%s (%s)" % (search_result["snippet"]["title"],
search_result["id"]["videoId"]))
videos_ids.append("%s" % (search_result["id"]["videoId"]))
elif search_result["id"]["kind"] == "youtube#channel":
channels.append("%s (%s)" % (search_result["snippet"]["title"],
search_result["id"]["channelId"]))
elif search_result["id"]["kind"] == "youtube#playlist":
playlists.append("%s (%s)" % (search_result["snippet"]["title"],
search_result["id"]["playlistId"]))
return videos_ids[0]
Теперь я получаю следующую ошибку:
AttributeError: 'str' object has no attribute 'authorize'
что не так, что мне не хватает?