【问题标题】:How do i go about adding a two-factor authentication code to a python request?如何向 python 请求添加双因素身份验证代码?
【发布时间】:2019-03-27 03:25:55
【问题描述】:

我在 python 中为 github 整理了一个发布请求,但我被要求添加所需的两因素身份验证代码。我需要将它添加到某处的有效载荷中吗?有什么想法吗?这是我正在使用的有效负载

  ```r = requests.post("https://api.github.com/gists/ 
              access_token="token",
              data=data, json=data,
              auth=requests.auth.HTTPBasicAuth("username", 
              "password"), headers=headers)```

【问题讨论】:

    标签: python-3.x api github request


    【解决方案1】:

    token 应该是 Authorization 标头的路径,as in this gist:

    GITHUB_API="https://api.github.com"
    API_TOKEN='your_token_goes_here'
    #form a request URL
    url=GITHUB_API+"/gists"
    print "Request URL: %s"%url
    
    #print headers,parameters,payload
    headers={'Authorization':'token %s'%API_TOKEN}
    params={'scope':'gist'}
    payload={"description":"GIST created by python code","public":True,"files":{"python request module":{"content":"Python requests has 3 parameters: 1)Request URL\n 2)Header Fields\n 3)Parameter \n4)Request body"}}}
    
    #make a requests
    res=requests.post(url,headers=headers,params=params,data=json.dumps(payload))
    

    来源自 GitHub 官方文档:“Authenticating for SAML SSO”

    【讨论】:

      猜你喜欢
      • 2017-04-04
      • 2022-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多