【问题标题】:Get token from a url in python3从python3中的url获取令牌
【发布时间】:2019-11-07 18:58:01
【问题描述】:

我有一个 python 代码,我在其中使用凭据从 url 获取令牌。它是从邮递员那里工作的。但不是来自python3。

headers = {'Content-type': 'Application/json', 'Accept': 'Application/json'}
data={ "username" : "someuser", "authSource" : "ADS", "password" : "somepasswd"}
req = requests.post(('https://example.com/suite-api/api/auth/token/acquire', data, headers=headers).json())
print(req)

上面的代码不起作用。它应该生成一个带有一些随机字符的令牌。

我希望输出为 7aaf-321b-82ab-7f55-2233891adb::5sde-3wqa-8sab

【问题讨论】:

    标签: python-3.x


    【解决方案1】:

    看来您的发帖请求是错误的。应该是这样的

    headers = {'Content-type': 'Application/json', 'Accept': 'Application/json'}
    data={ "username" : "someuser", "authSource" : "ADS", "password" : "somepasswd"}
    req = requests.post('https://example.com/suite-api/api/auth/token/acquire', data, headers=headers).json() #notice the () here
    print(req)
    

    你的 () at requests 放错了。

    【讨论】:

      猜你喜欢
      • 2016-07-18
      • 2016-12-13
      • 1970-01-01
      • 2020-04-13
      • 2013-06-13
      • 2023-01-10
      • 2019-04-01
      • 1970-01-01
      • 2015-07-08
      相关资源
      最近更新 更多