我是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)
如果auth方法确实是gssapi
,则可能需要使用HTTPNegotiateAuth
中的requests_negotiate
:
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