Skip to content
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

cffi_curl RequestsError: Failed to perform, curl: (55) Recv failure: Connection reset by peer #29

Closed
moehmeni opened this issue Mar 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@moehmeni
Copy link
Owner

When I am writing Genius as:

class Genius(LRCProvider):
    """Genius provider class"""

    SEARCH_ENDPOINT = "https://genius.com/api/search/multi?per_page=5&q="

    def get_lrc(self, search_term: str) -> Optional[str]:
        params = {"q": search_term, "per_page": 5}
        cookies = {
            "obuid": "e3ee67e0-7df9-4181-8324-d977c6dc9250",
        }
        r = self.session.get(self.SEARCH_ENDPOINT, params=params, cookies=cookies)
        if not r.ok:
            return None
        data = r.json()
        data = data["response"]["sections"][1]["hits"]
        if not data:
            return None
        url = data[0]["result"]["url"]
        soup = generate_bs4_soup(self.session, url)
        els = soup.find_all("div", attrs={"data-lyrics-container": True})
        if not els:
            return None
        lrc = ""
        for el in els:
            lrc += el.get_text(separator="\n", strip=True).replace("\n[", "\n\n[")
        return lrc

I get this error when running tests:

Traceback (most recent call last):
  File "/Users/mmomeni/Library/Caches/pypoetry/virtualenvs/syncedlyrics-oRcQejbK-py3.9/lib/python3.9/site-packages/curl_cffi/requests/session.py", line 843, in request
    c.perform()
  File "/Users/mmomeni/Library/Caches/pypoetry/virtualenvs/syncedlyrics-oRcQejbK-py3.9/lib/python3.9/site-packages/curl_cffi/curl.py", line 291, in perform
    self._check_error(ret, "perform")
  File "/Users/mmomeni/Library/Caches/pypoetry/virtualenvs/syncedlyrics-oRcQejbK-py3.9/lib/python3.9/site-packages/curl_cffi/curl.py", line 134, in _check_error
    raise error
curl_cffi.curl.CurlError: Failed to perform, curl: (55) Recv failure: Connection reset by peer. See https://curl.se/libcurl/c/libcurl-errors.html first for more details.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/mmomeni/Documents/Github/syncedlyrics/syncedlyrics/cli.py", line 45, in cli_handler
    lrc = search(
  File "/Users/mmomeni/Documents/Github/syncedlyrics/syncedlyrics/__init__.py", line 60, in search
    _l = provider.get_lrc(search_term)
  File "/Users/mmomeni/Documents/Github/syncedlyrics/syncedlyrics/providers/genius.py", line 26, in get_lrc
    soup = generate_bs4_soup(self.session, url)
  File "/Users/mmomeni/Documents/Github/syncedlyrics/syncedlyrics/utils.py", line 33, in generate_bs4_soup
    r = session.get(url)
  File "/Users/mmomeni/Library/Caches/pypoetry/virtualenvs/syncedlyrics-oRcQejbK-py3.9/lib/python3.9/site-packages/curl_cffi/requests/session.py", line 847, in request
    raise RequestsError(str(e), e.code, rsp) from e
curl_cffi.requests.errors.RequestsError: Failed to perform, curl: (55) Recv failure: Connection reset by peer. See https://curl.se/libcurl/c/libcurl-errors.html first for more details.

When I change

soup = generate_bs4_soup(self.session, url)

to

import requests
soup = generate_bs4_soup(requests, url)

it just works.
I would like to replace cffi_curl by requests again since it also did not have a problem with Deezer.

@moehmeni moehmeni added the bug Something isn't working label Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant