Skip to content

Commit

Permalink
Add SSL Cert verification parameter; version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
barrust committed Jul 28, 2023
1 parent 6f95028 commit 6c9b94b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,8 +1,9 @@
# MediaWiki Changelog

## Future Release
## Version 0.7.3

* Add `unordered_options` to the `DisambiguationError` to attempt to get options in the order presented on the page; [issue #124](https://github.com/barrust/mediawiki/issues/124)
* Add [verify SSL support](https://requests.readthedocs.io/en/latest/user/advanced/#ssl-cert-verification) by passing info directly to the requests library.

## Version 0.7.2

Expand Down
20 changes: 17 additions & 3 deletions mediawiki/mediawiki.py
Expand Up @@ -25,7 +25,7 @@
from .utilities import memoize

URL = "https://github.com/barrust/mediawiki"
VERSION = "0.7.2"
VERSION = "0.7.3"


class MediaWiki(object):
Expand Down Expand Up @@ -67,6 +67,7 @@ class MediaWiki(object):
"_use_cache",
"_is_logged_in",
"_proxies",
"_verify_ssl",
]

def __init__(
Expand All @@ -81,6 +82,7 @@ def __init__(
username=None,
password=None,
proxies=None,
verify_ssl=True,
):
""" Init Function """
self._version = VERSION
Expand All @@ -94,6 +96,8 @@ def __init__(
self._session = None
self._user_agent = ("python-mediawiki/VERSION-{0}" "/({1})/BOT").format(VERSION, URL)
self._proxies = None
self._verify_ssl = None
self.verify_ssl = verify_ssl
# set libary parameters
if user_agent is not None:
self.user_agent = user_agent
Expand Down Expand Up @@ -227,6 +231,16 @@ def timeout(self, timeout):
return
self._timeout = float(timeout) # allow the exception to be raised

@property
def verify_ssl(self):
""" bool: Verify SSL when using requests """
return self._verify_ssl

@verify_ssl.setter
def verify_ssl(self, verify_ssl):
""" Set request verify SSL parameter """
self._verify_ssl = bool(verify_ssl)

@property
def language(self):
""" str: The API URL language, if possible this will update the API \
Expand Down Expand Up @@ -971,14 +985,14 @@ def __cat_tree_rec(self, cat, depth, tree, level, categories, links):
def _get_response(self, params):
""" wrap the call to the requests package """
try:
return self._session.get(self._api_url, params=params, timeout=self._timeout).json()
return self._session.get(self._api_url, params=params, timeout=self._timeout, verify=self._verify_ssl).json()
except JSONDecodeError:
return {}

def _post_response(self, params):
""" wrap a post call to the requests package """
try:
return self._session.post(self._api_url, data=params, timeout=self._timeout).json()
return self._session.post(self._api_url, data=params, timeout=self._timeout, verify=self._verify_ssl).json()
except JSONDecodeError:
return {}

Expand Down

0 comments on commit 6c9b94b

Please sign in to comment.