2014-06-26 13 views
5

Ich habe ein Problem mit fehlenden erforderlichen Attribut für CUPS-Get-Devices. Grundsätzlich möchte ich Liste der verfügbaren Drucker mit IPP und CUPS mit https://www.npmjs.org/package/ipp erhalten.IPP fehlt Attribut auf CUPS-Get-Devices mit node.js ipp-Modul

Ich habe CUPS-Get-Devices in das Paket implementiert, da es das Attribut für das Paket nicht unterstützt, aber ich bekomme es funktioniert. Problem ist, dass die Antwort mit "status-message" antwortet: "Fehlende erforderliche Attribute". und mir die Liste der Drucker nicht geben.

var uri = "http://localhost:631" 
var data = ipp.serialize({ 
    "operation": "CUPS-Get-Printers", 
    "operation-attributes-tag": { 
    "attributes-charset": 'utf-8', 
    "attributes-natural-language": 'en-us', 
    "limit": 10 
} 
}); 

ipp.request(uri, data, function(err, res){ 
    if(err){ 
    return console.log(err); 
    } 
    console.log(JSON.stringify(res,null,2)); 
}); 

Die Antwort ist

{ 
    "version": "2.0", 
    "statusCode": "client-error-bad-request", 
    "id": 67392993, 
    "operation-attributes-tag": { 
    "attributes-charset": "utf-8", 
    "attributes-natural-language": "en-us", 
    "status-message": "Missing required attributes." 
    } 
} 

Die Dokumentation sagt nichts über andere erforderliche Parameter http://www.cups.org/documentation.php/spec-ipp.html#CUPS_GET_PRINTERS

jemand, wo ist das Problem Kennt? Vielen Dank!

Antwort

2

Dieser Code funktioniert für mich, mit einer unmodifizierten Ipp-Bibliothek und mit CUPS 1.7.3. Meine beste Vermutung ist, dass Sie einen Tippfehler oder etwas gemacht haben, als Sie die Bibliothek geändert haben.

var ipp = require('ipp'); 

// Add missing operation code 
ipp.operations['CUPS-Get-Printers'] = 0x4002; 

// The rest is identical to your code: 

var uri = "http://localhost:631"; 
var data = ipp.serialize({ 
    "operation": "CUPS-Get-Printers", 
    "operation-attributes-tag": { 
    "attributes-charset": 'utf-8', 
    "attributes-natural-language": 'en-us', 
    "limit": 10 
    } 
}); 

ipp.request(uri, data, function(err, res){ 
    if(err){ 
    return console.log(err); 
    } 
    console.log(JSON.stringify(res,null,2)); 
});