Python change Accept-Language using requests

mihasa picture mihasa · May 31, 2015 · Viewed 9k times · Source

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?

Answer

MattDMo picture MattDMo · May 31, 2015

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.