diff --git a/CHANGES.md b/CHANGES.md index d03c9dea..318bfd6b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -94,6 +94,7 @@ * Fix saving root dirs * Change pushbullet from urllib2 to requests * Change to make pushbullet error messages clearer +* Change pyNMA use of urllib to requests (ref:hacks.txt) [develop changelog] * Update Requests library 2.7.0 (ab1f493) to 2.7.0 (8b5e457) diff --git a/HACKS.txt b/HACKS.txt index 3e2e9fe6..5aea55dc 100644 --- a/HACKS.txt +++ b/HACKS.txt @@ -4,3 +4,4 @@ Libs with customisations... /lib/requests/packages/urllib3/connectionpool.py /lib/requests/packages/urllib3/util/ssl_.py /lib/cachecontrol/caches/file_cache.py +/lib/pynma/pynma.py \ No newline at end of file diff --git a/lib/pynma/pynma.py b/lib/pynma/pynma.py index a8675827..e735eddd 100644 --- a/lib/pynma/pynma.py +++ b/lib/pynma/pynma.py @@ -3,15 +3,7 @@ from . import __version__ from xml.dom.minidom import parseString -try: - from http.client import HTTPSConnection -except ImportError: - from httplib import HTTPSConnection - -try: - from urllib.parse import urlencode -except ImportError: - from urllib import urlencode +import requests class PyNMA(object): @@ -126,12 +118,9 @@ class PyNMA(object): if 'POST' == method: headers['Content-type'] = 'application/x-www-form-urlencoded' - http_handler = HTTPSConnection(self.api_server) - http_handler.request(method, path, urlencode(args), headers) - resp = http_handler.getresponse() - try: - res = self._parse_response(resp.read()) + resp = requests.post('%s:443%s' % (self.api_server, path), data=args, headers=headers).text + res = self._parse_response(resp) except Exception as e: res = {'type': 'pynmaerror', 'code': 600,