Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法从Spotipy API中提取歌曲封面艺术,即使它在打印输出字典时可见_Python_Api_Dictionary_Spotipy - Fatal编程技术网

Python 无法从Spotipy API中提取歌曲封面艺术,即使它在打印输出字典时可见

Python 无法从Spotipy API中提取歌曲封面艺术,即使它在打印输出字典时可见,python,api,dictionary,spotipy,Python,Api,Dictionary,Spotipy,这是打印的dic: {'album': {'album_type': 'single', 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/6BrvowZBreEkXzJQMpL174'}, 'href': 'https://api.spotify.com/v1/artists/6BrvowZBreEkXzJQMpL174', 'id': '6BrvowZBreEkXzJQMp

这是打印的
dic

{'album': {'album_type': 'single',
  'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/6BrvowZBreEkXzJQMpL174'},
    'href': 'https://api.spotify.com/v1/artists/6BrvowZBreEkXzJQMpL174',
    'id': '6BrvowZBreEkXzJQMpL174',
    'name': 'Hardwell',
    'type': 'artist',
    'uri': 'spotify:artist:6BrvowZBreEkXzJQMpL174'}],
  'available_markets': ['AD',
   'AE',
   'AL',
   'AR',
   'AT',
   'AU',
   'BA',
   'BE',
   'BG',
   'BH',
   'BO',
   'BR',
   'BY',
   'CA',
   'CH',
   'CL',
   'CO',
   'CR',
   'CY',
   'CZ',
   'DE',
   'DK',
   'DO',
   'DZ',
   'EC',
   'EE',
   'EG',
   'ES',
   'FI',
   'FR',
   'GB',
   'GR',
   'GT',
   'HK',
   'HN',
   'HR',
   'HU',
   'ID',
   'IE',
   'IL',
   'IN',
   'IS',
   'JO',
   'JP',
   'KW',
   'KZ',
   'LB',
   'LI',
   'LT',
   'LU',
   'LV',
   'MA',
   'MC',
   'MD',
   'ME',
   'MK',
   'MT',
   'MX',
   'MY',
   'NI',
   'NL',
   'NO',
   'NZ',
   'OM',
   'PA',
   'PE',
   'PH',
   'PL',
   'PS',
   'PT',
   'PY',
   'QA',
   'RO',
   'RS',
   'RU',
   'SA',
   'SE',
   'SG',
   'SI',
   'SK',
   'SV',
   'TN',
   'TR',
   'TW',
   'UA',
   'US',
   'UY',
   'VN',
   'XK',
   'ZA'],
  'external_urls': {'spotify': 'https://open.spotify.com/album/14SHciJYQ4DnKzprcUzE1z'},
  'href': 'https://api.spotify.com/v1/albums/14SHciJYQ4DnKzprcUzE1z',
  'id': '14SHciJYQ4DnKzprcUzE1z',
  'images': [{'height': 640,
    'url': 'https://i.scdn.co/image/ab67616d0000b27397e4c7870cffac76662a92fd',
    'width': 640},
   {'height': 300,
    'url': 'https://i.scdn.co/image/ab67616d00001e0297e4c7870cffac76662a92fd',
    'width': 300},
   {'height': 64,
    'url': 'https://i.scdn.co/image/ab67616d0000485197e4c7870cffac76662a92fd',
    'width': 64}],
  'name': 'Spaceman',
  'release_date': '2012-02-06',
  'release_date_precision': 'day',
  'total_tracks': 1,
  'type': 'album',
  'uri': 'spotify:album:14SHciJYQ4DnKzprcUzE1z'},
 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/6BrvowZBreEkXzJQMpL174'},
   'href': 'https://api.spotify.com/v1/artists/6BrvowZBreEkXzJQMpL174',
   'id': '6BrvowZBreEkXzJQMpL174',
   'name': 'Hardwell',
   'type': 'artist',
   'uri': 'spotify:artist:6BrvowZBreEkXzJQMpL174'}],
 'available_markets': [],
 'disc_number': 1,
 'duration_ms': 379260,
 'explicit': False,
 'external_ids': {'isrc': 'NLCY31100367'},
 'external_urls': {'spotify': 'https://open.spotify.com/track/1Ca2ELRlvACAeI7xz9c9jR'},
 'href': 'https://api.spotify.com/v1/tracks/1Ca2ELRlvACAeI7xz9c9jR',
 'id': '1Ca2ELRlvACAeI7xz9c9jR',
 'is_local': False,
 'is_playable': True,
 'name': 'Spaceman',
 'popularity': 53,
 'preview_url': 'https://p.scdn.co/mp3-preview/3e53578aa98127b4157b154a9714049d778393c5?cid=1d342fbcf9fd42a1b65ba5e7e369b991',
 'track_number': 1,
 'type': 'track',
 'uri': 'spotify:track:1Ca2ELRlvACAeI7xz9c9jR'}
我需要拉这个:

'images': [{'height': 640,
        'url': 'https://i.scdn.co/image/ab67616d0000b27397e4c7870cffac76662a92fd',
        'width': 640},
       {'height': 300,
        'url': 'https://i.scdn.co/image/ab67616d00001e0297e4c7870cffac76662a92fd',
        'width': 300},
       {'height': 64,
        'url': 'https://i.scdn.co/image/ab67616d0000485197e4c7870cffac76662a92fd',
        'width': 64}]
这似乎很容易,但当我输出dic.keys()时,我得到了以下结果:

dict_keys(['album', 'artists', 'available_markets', 'disc_number', 'duration_ms', 'explicit', 'external_ids', 'external_urls', 'href', 'id', 'is_local', 'is_playable', 'name', 'popularity', 'preview_url', 'track_number', 'type', 'uri'])

这是斯波蒂的问题吗?任何帮助都将不胜感激。

Spotify API没有任何功能,“图像”键位于“相册”中

试试这个:

images = dic['album']['images']