Python BeautifulSoup does not print()
<p>Following beautifulsoup script shows no output. Did i miss anything?
It was intended to hit some of the prints.</p>

<pre><code>from urllib.request import urlopen
from urllib.error import HTTPError
from bs4 import BeautifulSoup
import sys

url1 = "https://www.youtube.com/watch?v=APmUWC8S1_M"

def getTitle(url):
    try:
        html = urlopen(url)
    except HTTPError as e:
        print(e)
        return None
    try:
        bsObj = BeautifulSoup(html.read())
    except AttributeError as e:
        return None
    return bsObj

    title = getTitle(url1)

    if title == None:
        print("None at URL: " + url1)
    else:
        print(title)
</code></pre>

<p>This worked for me:</p>

<pre><code>from urllib.request import urlopen
from urllib.error import HTTPError
from bs4 import BeautifulSoup
import sys


def getContent(url):
    try:
        html = urlopen(url)
    except HTTPError as e:
        print(e)
        return None
    try:
        bsObj = BeautifulSoup(html.read())
    except AttributeError as e:
        return None
    return bsObj

url1 = "https://www.youtube.com/watch?v=v5NeyI4-fdI"
content = getContent(url1)
if content == None:
    print("Conent could not be found at URL: " + url1)
else:
    print(content)
</code></pre>

python printing error-handling beautifulsoup