2

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
1
  • 1
    As far as I can see, your object has no such attribute. Did you mean to use just geofence_id (with no self)? That is the variable that you are passing into the method. Commented Apr 26, 2014 at 1:23

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.