请求算法服务报错TypeError(“\‘NoneType\‘ object is not subscriptable“,)解决方案

1、post和get的区别
2、params和data的区别

import json

import requests


# @service_export()
def call(arg, *args, **kwargs):
    return {
        "sum": arg["x"] + arg["y"]
    }


if __name__ == '__main__':
    arg = {
        "x": 1,
        "y": 2
    }
    r = call(arg)
    print(r)

    url = 'https://open-platform-gateway.wenne.com/algorithm/dev/alg102548/call'  # 接口 URL
    params = arg  # 参数
    headers = {
        "Content-Type": "application/json",
        "X-GW-Authorization": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhcHBJZCI6InQ3RWQwNUs3IiwiZXhwIjoxNjk4NzE2MjMwfQ.MGSMT0zYGyMvEd_NhqzuGvUXQ3GxkQYY2gx4UORLD2s"}

    response = requests.post(url, data=json.dumps(arg), headers=headers)
    response = json.loads(response.text)  # 将响应数据解析为字典
    print(response)

你可能感兴趣的:(前端,requests,python,接口)