python - 关键错误 = client_id -- django

标签 python django synapsepay

我有一个 API,用于我正在开发的项目。我收到客户端 ID 的关键错误,我必须传递该错误才能调用 api。我使用的 api 是 Synapse。如果有人知道导致错误的原因或我如何修复此关键错误,这将是一点帮助......这是完整的错误。

KeyError at /
'client_id_...6YiBl'
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 1.8.6
Exception Type: KeyError
Exception Value:    
'client_id_...YiBl'
Exception Location: C:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\lib\os.py in __getitem__, line 669
Python Executable:  C:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\python.exe
Python Version: 3.6.1
Python Path:    
['C:\\Users\\OmarJandali\\Desktop\\opentab\\opentab',
 'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\python36.zip',
 'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\DLLs',
 'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\lib',
 'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36',
 'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-packages']

这是代码:

import os
from synapse_pay_rest import Client

args = {
    'client_id': os.environ['client_id_...YiBl'],
    'client_secret': os.environ['client_secret_...C3IF'],
    'fingerprint': '599378e9a63ec2002d7dd48b',
    'ip_address': '127.0.0.1',
    'development_mode':True,
    'logging':False
}

client = Client(**args)

最佳答案

您的代码看起来应该直接使用键,而您正在尝试访问环境变量。

基本上,不要尝试通过 os.environ() 访问这些值,因为它会让您的应用程序搜索名为 client_id_...YiBl 的环境变量>.

from synapse_pay_rest import Client

args = {
    'client_id': 'client_id_...YiBl',
    'client_secret':'client_secret_...C3IF',
    'fingerprint': '599378e9a63ec2002d7dd48b',
    'ip_address': '127.0.0.1',
    'development_mode':True,
    'logging':False
}

client = Client(**args)

关于python - 关键错误 = client_id -- django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46084811/

相关文章:

python - 具有多个url匹配的Django url配置

python - SynapsePay 和 Django 用户问题的冲突实例

python - 同质数据常量列表

python - Python 中有类似 "void lambda"的东西吗?

python - Python3 While语法错误

python - Matplotlib 投影 3d 级别问题

Django CSRF 保护强制设置 "Vary: Cookie" header ,导致缓存效率低下

python - 如何在本地运行 OpenShift Django 项目?