Undefined index: HTTP_ACCEPT_LANGUAGE using BeatifulSoup/Python
Question: I'm learning Python and I'm trying to parse a webpage made with PHP using
BeautifulSoup. My problem is my script show this error:

    
    
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
    <h4>A PHP Error was encountered</h4>
    <p>Severity: Notice</p>
    <p>Message:  Undefined index: HTTP_ACCEPT_LANGUAGE</p>
    <p>Filename: hooks/detecta_idioma.php</p>
    <p>Line Number: 110</p>
    </div>
    

when I try to do this

    
    
    html = urllib.urlopen(url).read()
    web = BeautifulSoup(html,'html.parser')
    print web
    etiquetas = web('a')
    

I thought that this error for executing my script by command line instead of
using a web browser but, executing this script from Apache, I have the same
error.

Anyone know how can I define that for parsing the url?


Answer: Looks like the page requires you to have the `Accept-Language` header passed
along with your request. Here is an example how to do that with
[`requests`](http://docs.python-requests.org/en/master/):

    
    
    import requests
    
    url = "my url"
    
    response = requests.get(url, headers={"Accept-Language": "en-US,en"})
    html = response.content
    web = BeautifulSoup(html, 'html.parser')
    

