Python - 如何在Requests_HTML中添加NTLM认证?

0 投票
1 回答
22 浏览
提问于 2025-04-14 17:34

我想在使用requests_html创建一个GET请求时,传递一个认证对象。同时,我还想传递一个证书的文件路径。这是我目前的代码。

def get_url():
     s = HTMLSession()
     try:
         response = s.get(url)
     except Exception as e:
         logging.exception('Could not send get request: {}'.format(e))
     response.html.render()
     return response

1 个回答

0

在使用requests_html库创建一个获取请求时,如果你想传递一个认证对象和证书的文件路径,可以使用auth和verify这两个关键字参数。下面是一个如何做到这一点的例子:

import requests_html

def get_url():
    s = HTMLSession()
    try:
        response = s.get(url, auth=auth, verify=cert_path)
    except Exception as e:
        logging.exception('Could not send get request: {}'.format(e))
    response.html.render()
    return response

在这个例子中,auth是一个认证对象,而cert_path是证书的文件路径。

撰写回答