UnicodeDecodeError: 'ascii' codec can't decode byte 0xf0 in position 6233: ordinal not in range(128)

python, python-3.x, web-scraping

Solution

The error occurred because of .encode which works on a unicode object. So we need to convert the byte string to unicode string using

.decode('unicode_escape')

So the code will be:

#!/usr/bin/env python3.5.2

import urllib.request , urllib.parse


def start(url):
    source_code = urllib.request.urlopen(url).read()
    info = urllib.parse.parse_qs(source_code.decode('unicode_escape'))
    print(info)


start('https://www.youtube.com/watch?v=YfRLJQlpMNw')

Problem

I'm working on a new project but I can't fix the error in the title. Here's the code: ``` #!/usr/bin/env python3.5.2 import urllib.request , urllib.parse def start(url): source_code = urllib.request.urlopen(url).read() info = urllib.parse.parse_qs(source_code) print(info) start('https://www.youtube.com/watch?v=YfRLJQlpMNw') ```

Original source