New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expected str instance nonetype found #168
Comments
Here's full traceback:
|
Hi. You might be using an outdated version of the package. What version of LyricsGenius are you using? |
@allerter Hi, the newest one, I've updated it today. |
Please provide a minimal script so that I reproduce the error. |
I'm using this script:
And I'm getting this:
It happens only after searching for all lyrics. Some issue with empty lyrics (classified as |
Currently, there is no way to make from lyricsgenius import Genius
from lyricsgenius.song import Song
genius = Genius(xxx)
genius.remove_section_headers = True
artist = genius.search_artist(xxx, max_songs=0)
page = 1
while page:
res = genius.artist_songs(artist._id,
sort='popularity',
per_page=50,
page=page)
if res is None:
continue
for hit in res['songs']:
if hit['lyrics_state'] == 'complete':
lyrics = genius.lyrics(hit['url'])
song = Song(hit, lyrics)
# this will add both the songs where the artist is the primary artist and the ones where he is a feature artist
artist.songs.append(song)
# replace the line above with artist.add_song(song) if you only want to add songs where the artist is the primary artist
print('Added: {}'.format(hit['title']))
else:
print('Skipped: {}'.format(hit['title']))
page = res['next_page']
data = ' '.join(song.lyrics for song in artist.songs if song.lyrics is not None)
filename = 'lyrics.txt'
with open(filename, 'w', encoding='utf8') as f:
f.write(data) Both of the issues (the timeout and |
I've tried your solution, but still there is some kind of error:
This happens randomly, at different songs. In your code I only changed part with maximum songs. |
You shouldn't change the max_songs parameter as we're adding the songs manually, so all we need is an empty Artist object. I edited the script above and improved it a bit. |
I've tried a few more times, and last time it actually worked. I guess, time-out is Genius-related issue, since their API is not created for scraping songs lyrics. Thanks you! |
This particular issue happens because we're making a lot of requests and as you mentioned their API wasn't made for lyrics, so we have to download each song page separately. This causes the number of requests to rise and time-outs are bound to happen when we make so many HTTP requests. In your case, the timeout happens when the package tries to fetch the full song info (because the |
My code
Sometimes script can't find lyrics to one song, passes it and goes to another one. But when saving file, it gives this error:
Error at line XX: Expected str instance nonetype found genius lyrics
How do I fix this error so I'm able to save the lyrics, even if one or more is missing?
The text was updated successfully, but these errors were encountered: