Key Error = client_id — django

Question:

I have an api that i am using for a project that I am working on. I am getting a key errror for the client Id that I have to pass in order ot call the api. THe api that i am using is Synapse. If anyone knows what is cuasing the error or how I can fix this key error, it would be a lit of help… Here is the full error.

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:UsersOmarJandaliAppDataLocalProgramsPythonPython36libos.py in __getitem__, line 669
Python Executable:  C:UsersOmarJandaliAppDataLocalProgramsPythonPython36python.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']

here is the code:

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)
Asked By: Omar Jandali

||

Answers:

Your code looks like it should be using the keys directly, whereas you’re trying to access environment variables.

Basically, don’t try to access these values via os.environ(), as it will make your application search for an environment variable named 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)
Answered By: wkl
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.