トレースバック:
Traceback (most recent call last):
File "venues.py", line 22, in <module>
main()
File "venues.py", line 19, in main
print_category(category, 0)
File "venues.py", line 13, in print_category
print_category(subcategory, ident+1)
File "venues.py", line 10, in print_category
print u'%s: %s' % (category['name'].encode('utf-8'), category['id'])
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3: ordinal not in range(128)
コード:
# -*- coding: utf-8 -*-
# Using https://github.com/marcelcaraciolo/foursquare
import foursquare
# Prints categories and subcategories
def print_category(category, ident):
for i in range(0,ident):
print u'\t',
print u'%s: %s' % (category['name'].encode('utf-8'), category['id'])
for subcategory in category.get('categories', []):
print_category(subcategory, ident+1)
def main():
client = foursquare.Foursquare(client_id='id',
client_secret='secret')
for category in client.venues.categories()['categories']:
print_category(category, 0)
if __name__ == '__main__':
main()