# Buggy code
def _login(self):
    (username, password) = self._get_login_info()
    if username is None:
        self.raise_login_required("safaribooksonline.com account is required")

    headers = std_headers
    if "Referer" not in headers:
        headers["Referer"] = self._LOGIN_URL

    login_page = self._download_webpage(self._LOGIN_URL, None, "Downloading login form")

    csrf = self._html_search_regex(
        r"name='csrfmiddlewaretoken'\s+value='([^']+)'", login_page, "csrf token"
    )

    login_form = {
        "csrfmiddlewaretoken": csrf,
        "email": username,
        "password1": password,
        "login": "Sign In",
        "next": "",
    }

    request = sanitized_Request(
        self._LOGIN_URL, urlencode_postdata(login_form), headers=headers
    )
    login_page = self._download_webpage(request, None, "Logging in as %s" % username)

    if re.search(self._SUCCESSFUL_LOGIN_REGEX, login_page) is None:
        raise ExtractorError(
            "Login failed; make sure your credentials are correct and try again.",
            expected=True,
        )

    self.to_screen("Login successful")


# Traceback (AttributeError)
[vimeo] 149274392: Downloading webpage
[vimeo] 149274392: Extracting information
[vimeo] 149274392: Downloading webpage
[vimeo] 149274392: Downloading JSON metadata
[vimeo] 149274392: Downloading m3u8 information
[tudou] ayXy8TTcG0M: Downloading JSON metadata
[tudou] ayXy8TTcG0M: found 26 parts
[tudou] 400753010: Opening the info XML page

Traceback (most recent call last):
File "C:\Python35\lib\site-packages\django\core\handlers\base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Python35\lib\site-packages\django\core\handlers\base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:/Python projects/getvideo/getvideo\getvideo\views.py", line 175, in search
tudou_info = downloader.extract_info('http://www.tudou.com/programs/view/ayXy8TTcG0M/', download=False)
File "C:\Python35\lib\site-packages\youtube_dl\YoutubeDL.py", line 666, in extract_info
ie_result = ie.extract(url)
File "C:\Python35\lib\site-packages\youtube_dl\extractor\common.py", line 316, in extract
return self._real_extract(url)
File "C:\Python35\lib\site-packages\youtube_dl\extractor\tudou.py", line 85, in _real_extract
ext = (final_url.split('?')[0]).split('.')[-1]
AttributeError: 'NoneType' object has no attribute 'split'

# Fixed code
def _login(self):
    (username, password) = self._get_login_info()
    if username is None:
        self.raise_login_required("safaribooksonline.com account is required")

    headers = std_headers.copy()
    if "Referer" not in headers:
        headers["Referer"] = self._LOGIN_URL
    login_page_request = sanitized_Request(self._LOGIN_URL, headers=headers)

    login_page = self._download_webpage(
        login_page_request, None, "Downloading login form"
    )

    csrf = self._html_search_regex(
        r"name='csrfmiddlewaretoken'\s+value='([^']+)'", login_page, "csrf token"
    )

    login_form = {
        "csrfmiddlewaretoken": csrf,
        "email": username,
        "password1": password,
        "login": "Sign In",
        "next": "",
    }

    request = sanitized_Request(
        self._LOGIN_URL, urlencode_postdata(login_form), headers=headers
    )
    login_page = self._download_webpage(request, None, "Logging in as %s" % username)

    if re.search(self._SUCCESSFUL_LOGIN_REGEX, login_page) is None:
        raise ExtractorError(
            "Login failed; make sure your credentials are correct and try again.",
            expected=True,
        )

    self.to_screen("Login successful")