cffi_curl RequestsError: Failed to perform, curl: (55) Recv failure: Connection reset by peer
moehmeni opened this issue · 0 comments
moehmeni commented
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.