Beispiel #1
0
 def do_POST(self):
     self._set_headers()
     data = self.rfile.read()
     data_str = ju.decode_UTF8(data).replace("'", '"')  #Get data from POST
     data = json.loads(
         json.loads(data_str)['json'])['push']  #dict this bitch
     s = json.dumps(data, sort_keys=True, indent=4)
     print(s)  #print shit to be done
     handleMessage(data)
Beispiel #2
0
def open_remote_devices(apikey):
    try:
        devices = urllib.request.urlopen(
            "https://joinjoaomgcd.appspot.com/_ah/api"
            "/registration/v1/listDevices?apikey=" + apikey).read()
        try:
            return json.loads(ju.decode_UTF8(devices))
        except Exception as e:
            print("Bad unicode from server.")
            sys.exit(1)

    except urllib.error.HTTPError as e:
        print("Error code: ", e.code)
        sys.exit(1)
    except urllib.error.URLError as e:
        print("Are you connected to the internet?")
        print("Check your connection and try again")
        sys.exit(1)
Beispiel #3
0
def open_remote_devices(apikey=os.getenv('JOIN_API')):
    """

    :param apikey:
    :return:
    """
    try:
        _devices = urllib.request.urlopen(
            "https://joinjoaomgcd.appspot.com/_ah/api"
            "/registration/v1/listDevices?apikey=" + apikey).read()
        try:
            return json.loads(joincliUtils.decode_UTF8(_devices))
        except JSONDecodeError as e:
            raise Exception(f'Open remote devices using '
                            f'API key has failed:\n'
                            f'Error code: {e.code}: \n{e}')

    except urllib.error.HTTPError as e:
        raise Exception(f"Error code: {e.code}: \n{e}")
    except urllib.error.URLError as e:
        raise Exception(f"Are you connected to the internet?\n"
                        f"Check your connection and try again:\n"
                        f"Error code: {e.code}: \n{e}")