Timeout raised on search
See original GitHub issueDescribe the bug Timeouts are being raised when trying to search artists, making it impossible to use the package, sometimes it works sometimes it doesn’t, maybe timeout time should be increased?
Expected behavior It should find the artist via genius API, return a valid object without errors
To Reproduce
- Clean install python and pip
- Pip install lyricsgenius
- Write some code to search artists and save lyrics.
import lyricsgenius
import os
import sys
if __name__ == "__main__":
if(len(sys.argv) < 2):
print("Wrong usage, correct use: lyricsDownloader.py artist max_songs [,excluded_terms]")
quit()
#You can also use dotenv, as you wish.
genius_token = os.getenv('GENIUS_TOKEN')
#Genius comes back with a bunch of unwanted results, like Live shows and/or remixes, you may want to exclude that
excluded_terms = ["Live", "Remix", "Inspired", "Cape"] if sys.argv == 2 else sys.argv[3:]
genius = lyricsgenius.Genius(genius_token)
genius.skip_non_songs = True
genius.excluded_terms = excluded_terms
#Just hope to god they have entered the right parameters
artist = genius.search_artist(sys.argv[1], max_songs=sys.argv[2])
artist.save_lyrics()
- Receive the error
python .\Tools\lyricsDownloader.py "Kanye west" 1
Searching for songs by Kanye west...
Timeout raised and caught:
HTTPSConnectionPool(host='api.genius.com', port=443): Read timed out. (read timeout=5)
Traceback (most recent call last):
File ".\Tools\lyricsDownloader.py", line 23, in <module>
artist = genius.search_artist(sys.argv[1], max_songs=sys.argv[2])
File "...\AppData\Local\Programs\Python\Python38\lib\site-packages\lyricsgenius\genius.py", line 585, in search_artist
found_name = artist_info['artist']['name']
TypeError: 'NoneType' object is not subscriptable
Version info
- Package version 2.0.2
- OS: Windows
Additional context
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Connection Timeout with Elasticsearch - python - Stack Overflow
The connection timed out problem could occur if you are using Amazon Elastic Search service. es = Elasticsearch([{ ...
Read more >Solved: Timeout using ScriptRunner - Atlassian Community
Solved: Hi, when using the enhanced search of scriptrunner cloud I often run into the issue, that it raises the error message: "Search...
Read more >How to change the default timeout period for the Web Search
By default, if your users leave the Exclaimer Mail Archiver Web Search logged in and unattended, their session will timeout and they will...
Read more >Execution Timeout Expired. The timeout period elapsed prior ...
The timeout period elapsed prior to completion of the operation or the server is not responding. Normally it shouldm't take more than 2...
Read more >Solved: CoreHost FeatureClass.Search '3 minute timeout' on...
Search '3 minute timeout' on Federated FeatureService ... WriteLine("Exception raised after: " + timeSpan.Minutes + " minutes " + timeSpan.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Explanation
Hi. This is happening because in the pip version of the package (
pip install lyricsgenius
), timeout errors are caught, andNone
is returned as the response. But the problem is that one of the requests insidegenius.search_artist
returns None and the package then tries to access that Nonetype object which causes the error. You can’t really do anything about this as it happens inside the function unless you edit the source. But that’s unnecessary as I’ll explain in the solution.Solution
You have two options
pip install lyricsgenius
), but catchTypeError
s using a try/except clause and repeat the action.pip install git+https://github.com/johnwmillr/LyricsGenius
) and catchrequests.Timeout
errors. Also, you could setgenius.retries
to 3 or something so that the package will retry the request in case of timeout/http errors. (There’s a section about handling request errors in the docs). This version will soon be available on pip as well.No matter what solution you decide to go with, make sure to increase the request timeout by setting
genius.timeout
to a number higher than 5 (the default).Let’s keep this open untill the release of v3.0 in case other people face this issue as well.