Python,发送带头文件和cookie的请求

时间:2017-07-18 12:13:35

标签: python cookies header request python-requests

向需要身份验证的服务器发送python请求以下载文件。我正在尝试使用请求发送cookie和标头。发送此请求的格式是什么?

从chrome开发人员,我可以看到请求标头为: enter image description here

python请求:

Session = requests.Session()
cookies = browser.get_cookies()

response = Session.get(url)

tt = "ASPSESSIONIDSGSRSATR"
cookie = {tt:Session.cookies.get_dict().get(tt,""),
          cookies[2].get("name",""):cookies[2].get("value",""),
          cookies[0].get("name",""):cookies[0].get("value","")}


header = {"Host":"ecsxxxxxxxxxxxxxxxxxxxxx",
          "Connection": "keep-alive",
          "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
          "User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36",
          "Referer":"https://ecsxxxxxxxxxxxxxxxxxxxxx",
          "Accept-Encoding":"gzip, deflate, sdch",
          "Accept-Language":"en-US,en;q=0.8,fr;q=0.6"}

response = Session.get(url, cookies = cookie, headers = header)

1 个答案:

答案 0 :(得分:0)

  

评论:...如何接受用户名/ pword?

Using the Python Kerberos Module

  

Kerberos Basics

     

在服务器上设置Kerberos身份验证时,有两种基本操作模式   从客户端实现的角度来看,最简单的方法是使用Basic Auth将用户名和密码传递给服务器,然后服务器使用Kerberos域检查它们。

  

评论:这是一个kerberos服务器

有一个可选的

  

requests Kerberos/GSSAPI authentication library

     

此库添加了可选的Kerberos / GSSAPI身份验证支持,并支持相互身份验证。

     

基本GET用法:

import requests
from requests_kerberos import HTTPKerberosAuth
r = requests.get("http://example.org", auth=HTTPKerberosAuth())

SO:session auth in python