【问题标题】:Requests different between post auth like data and and get auth like parameterpost auth like data 和 get auth like parameter 之间的请求不同
【发布时间】:2020-01-31 09:37:52
【问题描述】:

我正在研究有关请求的内容,但遇到了问题。 这个请求之间有什么不同:(忽略 URL,这只是示例)

requests.get('https://api.github.com/user', auth=("Superuser", "SuperSecretPassword"))

还有这个:

login_form = {"username" : "Superuser", "password" : "SuperSecretPassword"}
requests.post('https://api.github.com/user', data = login_form)

我是初学者,所以我有点过度康复,在此先感谢您的建议。

【问题讨论】:

    标签: python authentication post get request


    【解决方案1】:

    有不同的身份验证方式,每个后端都支持不同类型的身份验证。

    Requests 模块具有一些被开发人员广泛使用的内置身份验证机制。 参考:https://requests.readthedocs.io/en/master/user/authentication/

    现在auth 参数将使用给定值进行一些计算并将其作为标头传递给后端 但是当您在 post 请求中传递数据时,它将作为 POST 请求参数传递给后端。

    如果您在上述参考中看到基本身份验证,您会发现它是 HTTPBasicAuth 的简写

    【讨论】:

      猜你喜欢
      • 2017-03-03
      • 1970-01-01
      • 2018-01-22
      • 2019-01-22
      • 2020-03-26
      • 2018-10-29
      • 2016-07-27
      • 2012-12-23
      • 2018-11-17
      相关资源
      最近更新 更多