Python BeautifulSoup find_all 'ascii' codec can't decode byte
Question: I'm using BeautifulSoup for extraction of the links to different electoral
subregions outcomes from [Krasnodar krai
elections](http://www.krasnodar.vybory.izbirkom.ru/region/region/krasnodar?action=show&root=1&tvd=2232000821586&vrn=2232000821581&region=23&global=&sub_region=23&prver=2&pronetvd=1&vibid=2232000821586&type=381).
The links from html could be detected using word 'option'. html snippet:

    
    
    <form name="go_reg">Нижестоящие избирательные комиссии:  <select name="gs"><option val="">---</option>
    <option value="http://www.krasnodar.vybory.izbirkom.ru/region/krasnodar?action=show&amp;root=123400103&amp;tvd=2232000821616&amp;vrn=2232000821581&amp;prver=2&amp;pronetvd=1&amp;region=23&amp;sub_region=23&amp;type=381&amp;vibid=2232000821616">1 Абинская</option>
    <option value="http://www.krasnodar.vybory.izbirkom.ru/region/krasnodar?action=show&amp;root=123402603&amp;tvd=2232000821591&amp;vrn=2232000821581&amp;prver=2&amp;pronetvd=1&amp;region=23&amp;sub_region=23&amp;type=381&amp;vibid=2232000821591">2 Анапская</option>
    

Here is my code:

    
    
    import urllib2
    from bs4 import BeautifulSoup
    contenturl = "http://www.krasnodar.vybory.izbirkom.ru/region/region/krasnodar?action=show&root=1&tvd=2232000821586&vrn=2232000821581&region=23&global=&sub_region=23&prver=2&pronetvd=1&vibid=2232000821586&type=381"
    soup = BeautifulSoup(urllib2.urlopen(contenturl).read(), 'html.parser', from_encoding = 'windows-1252')
    soup.find_all('option')
    

However, I got following error:

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

I tried to find the answer, and one of suggestions was to set the encoding
manually using "from_encoding" option, but this did not resolve the issue


Answer: If you change your beautiful soup open, you can avoid the error.

    
    
    from bs4 import BeautifulSoup
    from urllib.request import urlopen
    
    url = "http://www.krasnodar.vybory.izbirkom.ru/region/region/krasnodar?action=show&root=1&tvd=2232000821586&vrn=2232000821581&region=23&global=&sub_region=23&prver=2&pronetvd=1&vibid=2232000821586&type=381" #/air-jordan-1-retro-high-og-unc-white-dk-powder-blue-012304"
    page=urllib.request.urlopen(url)
    soup = BeautifulSoup(page.read())
    for myValue in soup.find_all('option'):
        try:
            print(myValue.get_text() + " : " + myValue.get("value"))
        except:
            print("")
    

It generates

    
    
    1 Àáèíñêàÿ : http://www.krasnodar.vybory.izbirkom.ru/region/krasnodar?action=show&root=123400103&tvd=2232000821616&vrn=2232000821581&prver=2&pronetvd=1&region=23&sub_region=23&type=381&vibid=2232000821616
    2 Àíàïñêàÿ : http://www.krasnodar.vybory.izbirkom.ru/region/krasnodar?action=show&root=123402603&tvd=2232000821591&vrn=2232000821581&prver=2&pronetvd=1&region=23&sub_region=23&type=381&vibid=2232000821591
    3 Àïøåðîíñêàÿ : http://www.krasnodar.vybory.izbirkom.ru/region/krasnodar?action=show&root=123400203&tvd=2232000821617&vrn=2232000821581&prver=2&pronetvd=1&region=23&sub_region=23&type=381&vibid=2232000821617
    ....etc
    

