Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python中捕获requests.POST的结果?_Python_Api_Postman - Fatal编程技术网

如何在Python中捕获requests.POST的结果?

如何在Python中捕获requests.POST的结果?,python,api,postman,Python,Api,Postman,我是Python新手,在Postman中测试API POST请求时尝试模拟捕获的结果。我基本上是在尝试捕获使用Post方法生成的令牌 我在《邮递员》中有以下详细信息,这给了我代币的详细信息 授权选项卡:类型:基本身份验证、用户名、密码 标题选项卡:内容类型:application/x-www-form-urlencoded,授权:这是自动填写的 正文选项卡:原始:授予类型=客户端凭据&范围=读取 现在,当我在Postman中使用上述详细信息运行时,它在结果中为我提供了访问令牌,但当我使用以下Py

我是Python新手,在Postman中测试API POST请求时尝试模拟捕获的结果。我基本上是在尝试捕获使用Post方法生成的令牌

我在《邮递员》中有以下详细信息,这给了我代币的详细信息

授权选项卡:类型:基本身份验证、用户名、密码

标题选项卡:内容类型:application/x-www-form-urlencoded,授权:这是自动填写的

正文选项卡:原始:授予类型=客户端凭据&范围=读取

现在,当我在Postman中使用上述详细信息运行时,它在结果中为我提供了访问令牌,但当我使用以下Python代码使用相同的详细信息时,我只得到响应变量的as结果

import requests
url = 'https://appurl.com/oauth/ls/connect/token'
body = 'grant_type=client_credentials&scope=read_snfa_unifiedgateway'
response = requests.post(
        url,
        body, 
        auth=HTTPBasicAuth('my_username', 'my_password'), headers={'Content-Type': 'application/x-www-form-urlencoded'}
        )
我如何更改上面的Python代码,以使我能够以我在Postman中获得的格式获得结果,如下所示,然后在下一个操作中为另一个POST方法使用access_令牌值

{
    "access_token": "eyJ0eXAiOiJKV1QiLCJhbsdfsdfsdfsdfcsdcsdvarglkwelkrmgmasdmnfjtugnasmdfisdfmmmmpeirhg_-e60s72zgV8Gn2hUiWwlelNQhJongUW6fxwD42c1N5u4R2JJdrj5V_bIwnvY_C_l5wHlIFSQRE1E-5KzP7WG9XjmV9oXRXXGjNhwRqEocGdiEMjcibyiYQNZmG2h-GbsTKvCc21hRNhyRF_y4mdwVUytAXT68TuwZxsTbjUzEvPdwd2JZaFnD9Elo7akSk2ROnRMxN70fsoLzEK71kbzoYkti1jX_V8i_s6K0wmLma-x4nc2kW5mpFM0R9NPqH-kGf-4ZUKim03frifpsGl6Nqo-eN5oZ-b6YgK56mSjxpxQ",
    "expires_in": 3600,
    "token_type": "Bearer"
}
使用response.json以dict格式获取结果。你可以用


access\u token=response.json['access\u token']

太好了。我有没有办法也加密这些凭证?我相信在脚本和发送到appAPI的请求期间,这些文件目前都是可读的。