在Python请求库的get方法中使用标头

问题描述:

因此,我最近偶然发现了这个功能强大的库,用于在Python中处理HTTP请求;在此处 http://docs.python-requests.org/en/latest/index.html.

So I recently stumbled upon this great library for handling HTTP requests in Python; found here http://docs.python-requests.org/en/latest/index.html.

我喜欢使用它,但是我不知道如何在我的get请求中添加标题.帮助吗?

I love working with it, but I can't figure out how to add headers to my get requests. Help?

根据 api ,所有标头都可以使用request.get传递:

According to the api, the headers can all be passed in using requests.get:

r=requests.get("http://www.example.com/", headers={"content-type":"text"})