首页 > 解决方案 > 如何在 python 中使用 request.get() 和 defaultCredentials?

问题描述

我正在使用下面的代码使用 VB.NET 从 URL 获取 html

Dim strURL As String = "https://abcdef.com/page.aspx"
Dim strOutput As String = ""
Dim wrResponse As WebResponse
Dim wrRequest As WebRequest = HttpWebRequest.Create(strURL)
wrRequest.UseDefaultCredentials = True
wrResponse = wrRequest.GetResponse()

我想在 Python 中实现相同的功能:

import requests
x = requests.get('https://abcdef.com/page.aspx',verify=False)
print(x.text)

但我得到了这个回应:

  <h2>401 - Unauthorized: Access is denied due to invalid credentials.</h2>
  <h3>You do not have permission to view this directory or page using the credentials that you supplied. 
  </h3>

这不起作用,因为该站点需要凭据。如何在请求中包含我的默认凭据?在我见过的所有解决方案中,人们都在硬编码用户名和密码。

标签: pythonpython-requestshttprequestwindows-authentication

解决方案


推荐阅读