即使重设了我的客户机密后,我仍然收到此错误(如另一个线程所建议)。它一直在说KeyError:'groups'
def getNearbyVenues(names, latitudes, longitudes, LIMIT=500, radius=1000):
venues_list=[]
for name, lat, lng in zip(names, latitudes, longitudes):
print(name)
# create the API request URL
url = 'https://api.foursquare.com/v2/venues/explore?&client_id={}&client_secret={}&v={}&ll={},{}&radius={}&limit={}'.format(
CLIENT_ID,
CLIENT_SECRET,
VERSION,
lat,
lng,
radius,
LIMIT)
# make the GET request
results = requests.get(url).json()["response"]['groups'][0]['items']
# return only relevant information for each nearby venue
venues_list.append([(
name,
lat,
lng,
v['venue']['name'],
v['venue']['location']['lat'],
v['venue']['location']['lng'],
v['venue']['categories'][0]['name']) for v in results])
nearby_venues = pd.DataFrame([item for venue_list in venues_list for item in venue_list])
nearby_venues.columns = ['Neighborhood',
'Neighborhood Latitude',
'Neighborhood Longitude',
'Venue',
'Venue Latitude',
'Venue Longitude',
'Venue Category']
return(nearby_venues)
BM_venues = getNearbyVenues(names=BM_Geo['Neighborhood'],
latitudes=BM_Geo['Latitude'],
longitudes=BM_Geo['Longitude'],
LIMIT=500)
print('The "BM_venues" dataframe has {} venues and {} unique venue types.'.format(
len(BM_venues['Venue Category']),
len(BM_venues['Venue Category'].unique())))
BM_venues.to_csv('BM_venues.csv', sep=',', encoding='UTF8')
BM_venues.head()
错误消息:
KeyError Traceback (most recent call last)
<ipython-input-62-54a931f38399> in <module>
2 latitudes=BM_Geo['Latitude'],
3 longitudes=BM_Geo['Longitude'],
----> 4 LIMIT=500)
5
6 print('The "BM_venues" dataframe has {} venues and {} unique venue types.'.format(
<ipython-input-61-9472bd079ca6> in getNearbyVenues(names, latitudes, longitudes, LIMIT, radius)
16
17 # make the GET request
---> 18 results = requests.get(url).json()["response"]['groups'][0]['items']
19
20 # return only relevant information for each nearby venue
KeyError: 'groups'
我希望有人能帮助我解决这个问题。预先感谢。
添加更多文本,否则我无法提交此问题:)