I have the following class:
class Connection(object):
defaults = {
'application_key':None,
}
def __init__(self, application_key="None"):
self.application_key = application_key or Connection.defaults.get('application_key')
def make_request(self, params=None, method=None):
url = URL_FORMAT % {
'params': params,
}
headers = {
'Authorization': 'Token token='+ self.application_key,
'content-type': 'application/json',
}
if method == "get":
request = requests.get(url, headers=headers)
if request.status_code == requests.codes.ok:
return request.json()
else:
raise APIError("%s status received (not 200)" % request.status_code)
elif method == "post":
request = requests.post(url, headers=headers)
request.status_code == requests.codes.ok
if request.status_code == requests.codes.ok:
return request.json()
else:
raise APIError("%s status received (not 200)" % request.status_code)
def get_geofence(self):
try:
data = self.make_request('geofences', 'get')
return data
except APIError:
raise GeofenceNotFound("Geofence not found")
def get_geofence_id(self, geofence_id=None):
try:
data = self.make_request('geofences/'+self.geofence_id+'/', 'get')
return data
except APIError:
raise GeofenceNotFound("Geofence not found with id #%s" % self.geofence_id)
The problem line seems to be data = self.make_request('geofences/'+self.geofence_id+'/', 'get') returning AttributeError: 'Connection' object has no attribute 'geofence_id'
I'm pretty stumped here.
asked Apr 26, 2014 at 1:22
Llanilek
3,4765 gold badges41 silver badges66 bronze badges
1 Answer 1
geofence_id is not a class attribute, it is a function parameter. Thus, you should just refer to is as geofence_id and not self.geofence_id.
answered Apr 26, 2014 at 1:30
user3525381
2271 silver badge4 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
geofence_id(with no self)? That is the variable that you are passing into the method.