在不同URL的python / django上执行相同的API调用

问题描述

我正在尝试通过相同的api调用来获取多个网上商店的所有订单,但是我不确定什么是最快/最好的方法来完成此操作。每个商店都有自己的KEY,SECRET和HOST,我正在尝试弄清楚如何遍历不同的商店,并在get_all_orders()的“ order” -json字典中获得结果。

正如您在下面看到的,我尝试遍历包含所有API_KEY,API_Secret和API_Hosts的API模型。 API_prefix必须保持不变。

有任何提示或建议吗?预先感谢!

这是一个小例子:

#   API_Key = "<KEY>"
#   API_Secret = "<SECRET>"
#   API_Host = "<HOST>"
    API_Prefix = "/api/rest/v1/"

def headers(method,uri,data):
for x in Api.objects.all():
    upper_method = str.upper(method)
    hash_string = x.API_Key + "|" + upper_method + "|" + uri + "|" + data
    hash = hash_string
    headers = {
        "x-hash": hash,"x-public": x.API_Key,}
    return headers


def get(path,data):
for x in Api.objects.all():
    uri = API_Prefix + path
    url = x.API_Host + uri
    headers = headers("GET",data)
    results = requests.get(url,data=data,headers=headers)
    return results


def get_all_orders(request):
res = get("/orders","")
if res.status_code == 200:
    orders = json.loads(res.text)
    return render(request,"orders.html",{'orders': orders})

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...