将R-GET方法转换为Python

2024-10-04 01:26:50 发布

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

我是Python新手;目前,我需要将下面的R代码转换为Python,我知道我需要使用请求库;但是,我不知道如何将authenticate(cibc_username, cibc_password,"gssnegotiate")转换成Python。那么,有人能帮我解决这个问题吗

R代码如下:

hr_page = GET(url, user_agent("""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko\)
Chrome/70.0.3538.77 Safari/537.36"""), authenticate(cibc_username, cibc_password,"gssnegotiate"), timeout(20000))

我写的是:

headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"}
data = {'username':cibc_username, 'password':cibc_password}
hr_page = requests.get(url, headers = headers, data = data, timeout = 20000)

Tags: 代码urlmozilladatawindowspageusernamehr
1条回答
网友
1楼 · 发布于 2024-10-04 01:26:50

如果auth方法确实是gssapi,则可能需要使用来自requests_negotiateHTTPNegotiateAuth

import requests
from requests_negotiate import HTTPNegotiateAuth

headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"}
response = requests.get(url, headers = headers, timeout = 20000, auth=HTTPNegotiateAuth(cibc_username,cibc_password))

更多信息here

相关问题 更多 >