heiner55 is right you should always use
Example with f-string(3.6),which make building string nicer.
+
,which replace space.Example with f-string(3.6),which make building string nicer.
lower()
and join()
with +,should work for most search word.import requests api_key = "b088cbedecd40b35dd89e90f55227ac2" artists_search = 'the rolling stone' artists_search = '+'.join(artists_search.lower().split()) artists_response = requests.get(f'http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist={artists_search}&api_key={api_key}&format=json') try: print(artists_response.json()['artist']['url']) except KeyError: print('Artists not found')
Output:https://www.last.fm/music/+noredirect/The+Rolling+Stone
If search for Bruno Mars same as over,and take out url used see that +
is used.Output:https://www.last.fm/music/Bruno+Mars