pythonpython-requestshttp-accept-language

Python change Accept-Language using requests


I'm new to python and trying to get some infos from IMDb using requests library. My code is capturing all data (e.g., movie titles) in my native language, but i would like to get them in english. How can i change the accept-language in requests to do that?


Solution

  • All you need to do is define your own headers:

    import requests
    
    url = "http://www.imdb.com/title/tt0089218/"
    headers = {"Accept-Language": "en-US,en;q=0.5"}
    r = requests.get(url, headers=headers)
    

    You can add whatever other headers you'd like to modify as well.