question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Timeout raised on search

See original GitHub issue

Describe 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

  1. Clean install python and pip
  2. Pip install lyricsgenius
  3. 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()
  1. 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:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
allertercommented, Dec 15, 2020

Explanation

Hi. This is happening because in the pip version of the package (pip install lyricsgenius), timeout errors are caught, and None is returned as the response. But the problem is that one of the requests inside genius.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

  1. Keep using the pip version (pip install lyricsgenius), but catch TypeErrors using a try/except clause and repeat the action.
  2. Upgrade to the latest version (pip install git+https://github.com/johnwmillr/LyricsGenius) and catch requests.Timeout errors. Also, you could set genius.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).

1reaction
allertercommented, Dec 24, 2020

Let’s keep this open untill the release of v3.0 in case other people face this issue as well.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found