8000 Updated standards and fixed problems with python 3.8 · marttottdc/wc-api-python@b6d08cf · GitHub
  • [go: up one dir, main page]

    Skip to content

    Commit b6d08cf

    Browse files
    authored
    Updated standards and fixed problems with python 3.8
    - Updated version - Removed percentage operator in favor of f-strings - Added HTTPBasicAuth to auth for stricter reading - Removed python from HTTPBasicAuth header, to make this API work with the latest version of python.
    1 parent 933a0fa commit b6d08cf

    File tree

    1 file changed

    +7
    -7
    lines changed

    1 file changed

    +7
    -7
    lines changed

    woocommerce/api.py

    Lines changed: 7 additions & 7 deletions
    Original file line numberDiff line numberDiff line change
    @@ -5,14 +5,15 @@
    55
    """
    66

    77
    __title__ = "woocommerce-api"
    8-
    __version__ = "2.1.1"
    8+
    __version__ = "2.1.2"
    99
    __author__ = "Claudio Sanches @ Automattic"
    1010
    __license__ = "MIT"
    1111

    1212
    from requests import request
    1313
    from json import dumps as jsonencode
    1414
    from time import time
    1515
    from woocommerce.oauth import OAuth
    16+
    from requests.auth import HTTPBasicAuth
    1617

    1718
    try:
    1819
    from urllib.parse import urlencode
    @@ -44,12 +45,12 @@ def __get_url(self, endpoint):
    4445
    api = "wc-api"
    4546

    4647
    if url.endswith("/") is False:
    47-
    url = "%s/" % url
    48+
    url = f"{url}/"
    4849

    4950
    if self.wp_api:
    5051
    api = "wp-json"
    5152

    52-
    return "%s%s/%s/%s" % (url, api, self.version, endpoint)
    53+
    return f"{url}{api}/{self.version}/{endpoint}"
    5354

    5455
    def __get_oauth_url(self, url, method, **kwargs):
    5556
    """ Generate oAuth1.0a URL """
    @@ -71,20 +72,20 @@ def __request(self, method, endpoint, data, params=None, **kwargs):
    7172
    url = self.__get_url(endpoint)
    7273
    auth = None
    7374
    headers = {
    74-
    "user-agent": "WooCommerce API Client-Python/%s" % __version__,
    75+
    "user-agent": f'WooCommerce API {__version__}',
    7576
    "accept": "application/json"
    7677
    }
    7778

    7879
    if self.is_ssl is True and self.query_string_auth is False:
    79-
    auth = (self.consumer_key, self.consumer_secret)
    80+
    auth = HTTPBasicAuth(self.consumer_key, self.consumer_secret)
    8081
    elif self.is_ssl is True and self.query_string_auth is True:
    8182
    params.update({
    8283
    "consumer_key": self.consumer_key,
    8384
    "consumer_secret": self.consumer_secret
    8485
    })
    8586
    else:
    8687
    encoded_params = urlencode(params)
    87-
    url = "%s?%s" % (url, encoded_params)
    88+
    url = f"{url}?{encoded_params}"
    8889
    url = self.__get_oauth_url(url, method, **kwargs)
    8990

    9091
    if data is not None:
    @@ -122,4 +123,3 @@ def delete(self, endpoint, **kwargs):
    122123
    def options(self, endpoint, **kwargs):
    123124
    """ OPTIONS requests """
    124125 3A25
    return self.__request("OPTIONS", endpoint, None, **kwargs)
    125-

    0 commit comments

    Comments
     (0)
    0