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

Problems with SSLError #53

Open
PeterBremer-at-Philips opened this issue May 19, 2022 · 4 comments
Open

Problems with SSLError #53

PeterBremer-at-Philips opened this issue May 19, 2022 · 4 comments

Comments

@PeterBremer-at-Philips
Copy link

The initial tests as published, just do not work:
from pyradios import RadioBrowser
rb = RadioBrowser()
rb.search(name="BBC Radio 1", name_exact=True)

Gives
SSLError: HTTPSConnectionPool(host='at1.api.radio-browser.info', port=443): Max retries exceeded with url: /json/stations/search?name=BBC+Radio+1&nameExact=true (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)')))

@PeterBremer-at-Philips
Copy link
Author

A solution which works for me is to add verify=False in function called at line 22 of radios.py:

def get(self, url, **kwargs):
    resp = self._session.get(url, headers=self._headers,
                             verify=False,
                             params=kwargs)
    if resp.status_code == 200:
        return resp.json()
    return resp.raise_for_status()

@andreztz
Copy link
Owner

@PeterBremer-Ph I have no time to investigate what is going on, it seems to be a problem with the upstream servers. Anyway, following your suggestion, as soon as possible I will add a way to disable ssl directly in the main class.

rb = RadioBrowser(ssl=False)

@PeterBremer-at-Philips
Copy link
Author

PeterBremer-at-Philips commented May 26, 2022

Great!
Perhaps than also make sure that the following is or will be added (optionally?):
from requests.packages import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

@PeterBremer-at-Philips
Copy link
Author

Done, changed radios.py (version 1.0.2)

from requests.packages import urllib3

class Request:
def __init__(self, headers=None, session=None, ssl_verify=True):
self._headers = headers
self._session = self._init_session(session)
self.ssl_verify = ssl_verify

...
def get(self, url, **kwargs):
resp = self._session.get(url, headers=self._headers, verify=self.ssl_verify, params=kwargs)
if resp.status_code == 200:
return resp.json()
return resp.raise_for_status()


Radiobrowser:

def __init__(self, session=None, ssl_verify=True, diswarn=True, **kwargs):
if diswarn and not ssl_verify:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

self.base_url = pick_base_url()
self._fmt = 'json'
self.client = Request(headers=self.headers, session=session, ssl_verify=ssl_verify)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants