I'm working with Eventbrite api searching for some events, but at some point im trying to get some attributes out off the response using json.load() but getting this error when trying to print events_load.
Traceback (most recent call last):
File "/Users/jo/PycharmProjects/api-eventbrite/api-eventbrite.py", line 21, in <module>
events_load = json.load(events)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/__init__.py", line 265, in load
return loads(fp.read(),
AttributeError: 'EventbriteObject' object has no attribute 'read'
When printing events_dump i can perfectly see the full structure of the json response.
I think im bumping into some internals of python which im not aware off as a beginner. Can someone point me into a good explanation for this error. How can i understand what are the attributes and methods a certain object has ?
below the code
from eventbrite import Eventbrite
eventbrite = Eventbrite(my_auth_token)
events = eventbrite.get('/events/search/?q=lisboa&categories=102')
# events_dump = json.dumps(events, indent=4)
# print(events_dump)
events_load = json.load(events)
print(events_load)
How can i understand what are the attributes and methods a certain object has ?
Place print(dir(eventbrite))
and you will see all the functions and variables in the Eventbrite
obj. However I suspect you don't really care about that stuff and you want to see the key/values of the retrieved events. You can do something like:
from eventbrite import Eventbrite
eventbrite = Eventbrite(my_auth_token)
events = eventbrite.get('/events/search/?q=lisboa&categories=102')
for key, val in events.items():
print('{0}:\t{1}'.format(key,val))
There are more elagant ways to do it like pprint
, but I'll let you figure that out (I've provided the links). Also, I'd reccomend you start learning how to use Python's debugger pdb
to help you setup break points and view the values. Hope that helps.