Reputation: 21
My API call in Python returns no results. It exits with code 0 but there is nothing displayed. Is there something I am missing? I am still new to Python and got the code from a YouTube tutorial. I am using my own API Key. Here is the code:
#!/usr/bin/env python
#Learn how this works here: http://youtu.be/pxofwuWTs7c
import urllib.request
import json
locu_api = 'XXXXXXXXXXXX'
def locu_search(query):
api_key = locu_api
url = 'https://api.locu.com/v1_0/venue/search/?api_key=' + api_key
locality = query.replace(' ', '%20')
final_url = url + "&locality=" + locality + "&category=restaurant"
json_obj = urllib2.urlopen(final_url)
data = json.load(json_obj)
for item in data['objects']:
print (item['name'], item['phone'])
Upvotes: 1
Views: 154
Reputation: 188
You need to call your function first
locu_search('.....')
If there is no explicite exti(int) -> exit(0) is assumed.
Upvotes: 0
Reputation: 11140
Your script def
ines the function locu_search
, but you are not calling it; thus the script terminates successfully - having successfully done nothing of any value.
You need to call your function after it is defined, like:
def locu_search(query):
#snip
locu_search('San Francisco')
Upvotes: 1