2017-09-06 38 views
1

我有一個api,我正在使用我正在進行的項目。我得到了客戶端ID的一個關鍵錯誤,我必須通過它才能調用API。我正在使用的api是Synapse。如果有人知道是什麼引發了錯誤,或者我可以如何解決這個關鍵錯誤,那將會是一種幫助......這是完整的錯誤。關鍵錯誤= client_id - django

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) 
+0

我已經編輯出了代碼中的完整密碼/ id。我建議在Synapse中使它們失效併發布新的證書。 – birryree

+0

謝謝。我意識到後,我有我的客戶端ID和客戶端的祕密...大聲笑 –

回答

2

你的代碼看起來應該直接使用按鍵,而你試圖訪問的環境變量。

基本上,不要試圖通過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) 
+0

它的工作,非常感謝你。但我還有一個問題.. –

+0

@OmarJandali肯定的事情,有什麼問題嗎?隨意編輯它到您的原始問題,並讓我知道。 – birryree

+0

我有一個問題,我想知道如果你知道如何解決這個問題,我正在用用戶命令...以下是我得到的消息。 'AttributeError的在/ setup_profile/ 類型對象 '用戶' 不具有屬性 '創建' 請求 方法:\t POST 請求URL:\t http://127.0.0.1:8000/setup_profile/ Django的版本:\t 1.8.6 異常類型:\t AttributeError的 異常值:\t 對象類型 '用戶' 不具有屬性 '創建' 異常位置:\t C:\用戶\ OmarJandali \桌面\ opentab \ opentab \在createUserSynapse,線1104標籤\ views.py '@birryree –