【问题标题】:Python, sending a request with headers and cookiesPython,发送带有标头和 cookie 的请求
【发布时间】:2017-07-20 16:55:40
【问题描述】:

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

来自 chrome 开发人员,我可以看到请求标头为:

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)

【问题讨论】:

  • 你知道服务器使用的认证类型吗?
  • 没有。我如何找到它?
  • 如果有帮助的话,它是一个 Oracle EMC 服务器
  • @stovfl,这是通过本地代理服务器。该问题旨在验证来自外部服务器的下载。
  • @MalcolmMurdoch 这是一个kerberos服务器

标签: python cookies header request python-requests


【解决方案1】:

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

Using the Python Kerberos Module

Kerberos 基础知识

在服务器上设置 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())

所以:session auth in python

【讨论】:

  • 今天早上我在玩那个库,但是它如何接受用户名/密码?
猜你喜欢
  • 1970-01-01
  • 2011-10-01
  • 2020-12-31
  • 2016-11-10
  • 2011-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-15
相关资源
最近更新 更多