Forums

URLError at /youtube/ <urlopen error Tunnel connection failed: 403 Forbidden>

When I submit my form the error URLError at /youtube/ <urlopen error Tunnel connection failed: 403 Forbidden>

enter link description here

I'm not getting a 403 when submitting a url on your page

Here is the image: https://ibb.co/2P5MHcT

I am using pytube to download video from YouTube. And in my local server everything working well.

my views.py

def index(request):

form = Search()

if request.method == 'POST':
    form = Search(request.POST)

    if form.is_valid():
        url = form.cleaned_data.get('url')

        video = YouTube(url)

        stream = video.streams.filter()

        context = {
            'form': form,
            'video_title': video.title,
            'video_thumb': video.thumbnail_url,
            'stream': stream,
            'v_url': url[17:],
            'active_yt': 'active',
        }

        return render(request, 'yt_index.html', context)

context = {
    'form': form,
    'stream': None,
    'active_yt': 'active',
}

return render(request, 'yt_index.html', context)

The problem showing from YouTube object

Ah okay, youre probably running into the api whitelist -

https://help.pythonanywhere.com/pages/RequestingAllowlistAdditions/

https://www.pythonanywhere.com/whitelist/