【问题标题】:Convert R GET method into Python将 R GET 方法转换为 Python
【发布时间】:2020-03-13 13:51:57
【问题描述】:

我是 Python 新手;目前,我需要将下面的 R 代码转换为 Python,我知道我需要使用 requests 库;但是,我不知道如何将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)

【问题讨论】:

    标签: python r web-scraping python-requests httr


    【解决方案1】:

    如果auth方法确实是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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-05
      • 1970-01-01
      • 2021-05-15
      • 1970-01-01
      相关资源
      最近更新 更多