在FourSquarePython调用中得到一个KeyError: venues错误。

问题描述 投票:0回答:1

好吧,我是个新手,我认为我已经做了所有我应该做的事情,但我仍然得到一个KeyError:场地。我也试过用 "场地 "来代替,而且我在FourSquare还没有达到当天的最大配额)...... 我使用Jupyter Notebook来做这件事。

使用这个代码。

VERSION = '202700418'

RADIUS = 1000

LIMIT = 2

**url = 'https://api.foursquare.com/v2/venues/explore?client_id={}&client_secret={}&ll={},{}&v={}&radius={}&limit={}'.format(CLIENT_ID, CLIENT_SECRET, latitude, longitude, VERSION, RADIUS, LIMIT)
url
results = requests.get(url).json()**

我得到了2个结果(如本帖末尾所示)

当我试着把这些结果放到一个数据框架中时,我得到 "KeyError: venues"。

# assign relevant part of JSON to venues
venues = results['response']['venues']

# tranform venues into a dataframe
dataframe = json_normalize(venues)
dataframe.head()

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-29-5acf500bf9ad> in <module>
      1 # assign relevant part of JSON to venues
----> 2 venues = results['response']['venues']
      3 
      4 # tranform venues into a dataframe
      5 dataframe = json_normalize(venues)

KeyError: 'venues'

我真的不知道我哪里做错了... ... 我在其他地方也是这样做的... ... 但话说回来,就像我说的,我是新手... ... (我还没有把我的查询量调到最大,我也试过用 "地点 "来代替)... ... 谢谢你的帮助

FourSquareResults。

{'meta': {'code': 200, 'requestId': '5ec42de01a4b0a001baa10ff'},
 'response': {'suggestedFilters': {'header': 'Tap to show:',
   'filters': [{'name': 'Open now', 'key': 'openNow'}]},
  'warning': {'text': "There aren't a lot of results near you. Try something more general, reset your filters, or expand the search area."},
  'headerLocation': 'Cranford',
  'headerFullLocation': 'Cranford',
  'headerLocationGranularity': 'city',
  'totalResults': 20,
  'suggestedBounds': {'ne': {'lat': 40.67401708586377,
    'lng': -74.29300815204098},
   'sw': {'lat': 40.65601706786374, 'lng': -74.31669390523408}},
  'groups': [{'type': 'Recommended Places',
    'name': 'recommended',
    'items': [{'reasons': {'count': 0,
       'items': [{'summary': 'This spot is popular',
         'type': 'general',
         'reasonName': 'globalInteractionReason'}]},
      'venue': {'id': '4c13c8d2b7b9c928d127aa37',
       'name': 'Cranford Canoe Club',
       'location': {'address': '250 Springfield Ave',
        'crossStreet': 'Orange Avenue',
        'lat': 40.66022488705574,
        'lng': -74.3061084180977,
        'labeledLatLngs': [{'label': 'display',
          'lat': 40.66022488705574,
          'lng': -74.3061084180977},
         {'label': 'entrance', 'lat': 40.660264, 'lng': -74.306191}],
        'distance': 543,
        'postalCode': '07016',
        'cc': 'US',
        'city': 'Cranford',
        'state': 'NJ',
        'country': 'United States',
        'formattedAddress': ['250 Springfield Ave (Orange Avenue)',
         'Cranford, NJ 07016',
         'United States']},
       'categories': [{'id': '4f4528bc4b90abdf24c9de85',
         'name': 'Athletics & Sports',
         'pluralName': 'Athletics & Sports',
         'shortName': 'Athletics & Sports',
         'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/shops/sports_outdoors_',
          'suffix': '.png'},
         'primary': True}],
       'photos': {'count': 0, 'groups': []},
       'venuePage': {'id': '60380091'}},
      'referralId': 'e-0-4c13c8d2b7b9c928d127aa37-0'},
     {'reasons': {'count': 0,
       'items': [{'summary': 'This spot is popular',
         'type': 'general',
         'reasonName': 'globalInteractionReason'}]},
      'venue': {'id': '4d965995e07ea35d07e2bd02',
       'name': 'Mizu Sushi',
       'location': {'address': '103 Union Ave.',
        'lat': 40.65664427772896,
        'lng': -74.30343966195308,
        'labeledLatLngs': [{'label': 'display',
          'lat': 40.65664427772896,
          'lng': -74.30343966195308}],
        'distance': 939,
        'postalCode': '07016',
        'cc': 'US',
        'city': 'Cranford',
        'state': 'NJ',
        'country': 'United States',
        'formattedAddress': ['103 Union Ave.',
         'Cranford, NJ 07016',
         'United States']},
       'categories': [{'id': '4bf58dd8d48988d1d2941735',
         'name': 'Sushi Restaurant',
         'pluralName': 'Sushi Restaurants',
         'shortName': 'Sushi',
         'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/sushi_',
          'suffix': '.png'},
         'primary': True}],
       'photos': {'count': 0, 'groups': []}},
      'referralId': 'e-0-4d965995e07ea35d07e2bd02-1'}]}]}}
python jupyter-notebook python-3.6 foursquare
1个回答
0
投票

仔细看看你得到的响应--那里没有 "场地 "键。我看到最接近的是 "组 "列表,里面有 "项目 "列表,而单个项目有 "场地 "键。

© www.soinside.com 2019 - 2024. All rights reserved.