将 R GET 方法转换为 Python
Convert R GET method into 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)
如果认证方法确实是gssapi
,您可能需要使用HTTPNegotiateAuth
from 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
我是新手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)
如果认证方法确实是gssapi
,您可能需要使用HTTPNegotiateAuth
from 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