Python,发送带有头和cookies的请求

2024-10-01 02:27:54 发布

您现在位置:Python中文网/ 问答频道 /正文

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

从chrome developer,我可以看到请求头为: 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)

Tags: nameurlgetapplicationvaluecookieresponsesession
1条回答
网友
1楼 · 发布于 2024-10-01 02:27:54

Comments: ... how does that accept the username/pword?

Using the Python Kerberos Module

Kerberos Basics

When setting up Kerberos authentication on a server, there are two basic modes of operation.
The simplest from a client implementation point of view just uses Basic Auth to pass a username and password to the server, which then checks them with the Kerberos realm.


Comments: it's a kerberos server

有一个可选的

requests Kerberos/GSSAPI authentication library

This library adds optional Kerberos/GSSAPI authentication support and supports mutual authentication.

Basic GET usage:

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

所以:session auth in python

相关问题 更多 >