如何在python中将request.get()与defaultCredentials一起使用?

2024-07-08 10:58:29 发布

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

我使用下面的代码使用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>

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


Tags: tohttpscomstringaspageh2requests

热门问题