【问题标题】:Key Error = client_id -- django关键错误 = client_id -- django
【发布时间】:2018-02-15 12:15:44
【问题描述】:

我有一个用于我正在进行的项目的 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)

【问题讨论】:

  • 我已经编辑了您在代码中的完整秘密/ID。我建议在 Synapse 中使它们无效并颁发新凭据。
  • 谢谢。之后我意识到我有我的客户 ID 和客户密码......哈哈

标签: python django synapse


【解决方案1】:

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

基本上,不要尝试通过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)

【讨论】:

  • @OmarJandali 确定,有什么问题?随时将其编辑为您的原始问题并告诉我。
  • 我有一个问题,我想知道您是否知道如何解决我使用用户命令遇到的这个问题...以下是我收到的消息。 AttributeError at /setup_profile/ type object 'User' has no attribute 'create' Request Method: POST Request URL: http://127.0.0.1:8000/setup_profile/ Django Version: 1.8.6 Exception Type: AttributeError Exception Value: type object 'User' has no attribute 'create' Exception Location: C:\Users\OmarJandali\Desktop\opentab\opentab\tab\views.py in createUserSynapse, line 1104@birryree
猜你喜欢
  • 2013-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-01
相关资源
最近更新 更多