
import urllib.request
import json


class RESTfulApi:
    """
    Generic REST API call
    """
    def __init__(self):
        """
        Constructor
        """
        pass

    def request(self, url):
        """
        Web request
        :param: url: The url link
        :return JSON object
        """
        req = urllib.request.Request(url, None, headers={
            "Content-Type": "application/x-www-form-urlencoded",
            "Accept": "*/*",
            "User-Agent": "curl/7.24.0 (x86_64-apple-darwin12.0)"})
        res = urllib.request.urlopen(req)
        res = json.loads(res.read().decode('utf8'))
        return res




try:
    import urllib.request as urlrequest
except ImportError:
    import urllib as urlrequest

import json


class RESTfulApi:
    """
    Generic REST API call
    """
    def __init__(self):
        """
        Constructor
        """
        pass

    def request(self, url):
        """
        Web request
        :param: url: The url link
        :return JSON object
        """
        req = urlrequest.Request(url, None, headers={
            "Content-Type": "application/x-www-form-urlencoded",
            "Accept": "*/*",
            "User-Agent": "curl/7.24.0 (x86_64-apple-darwin12.0)"})
        res = urlrequest.urlopen(req)
        res = json.loads(res.read().decode('utf8'))
        return res



Support python 2 and 3 compatability
Support python 2 and 3 compatability

  
+ try:
+     import urllib.request as urlrequest
+ except ImportError:
- import urllib.request
+     import urllib as urlrequest
+ 
  import json
  
  
  class RESTfulApi:
      """
      Generic REST API call
      """
      def __init__(self):
          """
          Constructor
          """
          pass
  
      def request(self, url):
          """
          Web request
          :param: url: The url link
          :return JSON object
          """
-         req = urllib.request.Request(url, None, headers={
+         req = urlrequest.Request(url, None, headers={
              "Content-Type": "application/x-www-form-urlencoded",
              "Accept": "*/*",
              "User-Agent": "curl/7.24.0 (x86_64-apple-darwin12.0)"})
-         res = urllib.request.urlopen(req)
+         res = urlrequest.urlopen(req)
          res = json.loads(res.read().decode('utf8'))
          return res
  
  
  
Support python 2 and 3 compatability
## Code Before:

import urllib.request
import json


class RESTfulApi:
    """
    Generic REST API call
    """
    def __init__(self):
        """
        Constructor
        """
        pass

    def request(self, url):
        """
        Web request
        :param: url: The url link
        :return JSON object
        """
        req = urllib.request.Request(url, None, headers={
            "Content-Type": "application/x-www-form-urlencoded",
            "Accept": "*/*",
            "User-Agent": "curl/7.24.0 (x86_64-apple-darwin12.0)"})
        res = urllib.request.urlopen(req)
        res = json.loads(res.read().decode('utf8'))
        return res



## Instruction:
Support python 2 and 3 compatability
## Code After:

try:
    import urllib.request as urlrequest
except ImportError:
    import urllib as urlrequest

import json


class RESTfulApi:
    """
    Generic REST API call
    """
    def __init__(self):
        """
        Constructor
        """
        pass

    def request(self, url):
        """
        Web request
        :param: url: The url link
        :return JSON object
        """
        req = urlrequest.Request(url, None, headers={
            "Content-Type": "application/x-www-form-urlencoded",
            "Accept": "*/*",
            "User-Agent": "curl/7.24.0 (x86_64-apple-darwin12.0)"})
        res = urlrequest.urlopen(req)
        res = json.loads(res.read().decode('utf8'))
        return res


