<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def _query_nsot(url, headers, device=None):
    '''
    if a device is given, query nsot for that specific device, otherwise return
    all devices

    :param url: str
    :param headers: dict
    :param device: None or str
    :return:
    '''
    url = urlparse.urljoin(url, 'devices')
    ret = {}
    if not device:
        query = salt.utils.http.query(url, header_dict=headers, decode=True)
    else:
        url = urlparse.urljoin(url, device)
        query = salt.utils.http.query(url, header_dict=headers,
                                      decode=True)
    error = query.get('error')
    if error:
        log.error('can\'t get device(s) from nsot! reason: %s', error)
    else:
        ret = query['dict']

    return ret