Reputation: 1
I was running an application that requires the PytubeFix library to extract content from YouTube videos. It runs locally without any problems, but when I deploy it, it doesn’t work. On the server, it logs a message saying “Login required” with the video ID, as shown in the image.
OS : ubuntu 22.04
Python : 3.10
pytubefix : 6.6.2
In pytubefix, we can define use_oauth=True as shown below:
from pytubefix import YouTube
video = Youtube(url, use_oauth=True)
#rest of the code
When applying this, it prompts a message to authenticate with OAuth via a given URL and key. After authentication, we have to press Enter on the terminal. This worked fine in the local environment.
However, after deployed to EC2, we cannot perform this action
Issue - https://github.com/JuanBindez/pytubefix/issues/119
I have successfully come up with a solution as outlined in the steps below
venv/lib/python3.10/site-packages/pytubefix/__cache__/tokens.json
venv/lib/python3.10/site-packages/pytubefix
directory within your project.mkdir __cache__
) inside the pytubefix directory and create a file called "tokens.json" (touch tokens.json
) inside the __cache__ directorynano tokens.json
to open the file, paste the code, save it, and exitNow the issue is fixed, and videos are being extracted from YouTube without the “Login required” or “Private video” issues
Issue: You need to update the tokens.json file when the OAuth token expires
While this solution works for now, it is not consistent for long-term use. Is there a more sustainable solution for using this library over an extended period?
Upvotes: 0
Views: 596