错误:参数错误:除非设置了use_unauthenticated,否则需要用户名和密码

时间:2019-02-27 15:25:36

标签: ibm-watson speech-to-text

我正在尝试将STT服务与iam apikey一起使用。

如果我将IAM凭据设置为documentation shows(如下),则会出现错误:除非设置了use_unauthenticated,否则需要用户名和密码

this.map = new Map({
        target: "map",
        layers: [
            new TileLayer({
                source: new XYZ({
                    attributions: 'Tiles © <a href="https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer">ArcGIS</a>',
                    url: 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'
                })
            }),
        ],
        view: new View({
            center: fromLonLat([-8.455826, 40.168307]),
            rotation: 1.1344640138,
            easing: 0.5
        })
    });

    var vectorSource = new VectorSource({});

    var markersLayer = new VectorLayer({
        source: vectorSource,
    });

    this.map.addLayer(markersLayer);

    var point1 = new Point(
        fromLonLat([-8.455826, 40.168307])
    );

    var point2 = new Point(
        fromLonLat([-8.456819, 40.166388])
    );

    var marker = new Feature({
        geometry: point1,
        name: "My point",
    });

    vectorSource.addFeature(marker);

    var style = new Style({
        image: new CircleStyle({
            radius: 7,
            fill: new Fill({color: 'black'}),
            stroke: new Stroke({
                color: 'white', width: 2
            })
        })
    });

    marker.setStyle(style);

    setTimeout(function () {
        marker.setGeometry(point2);
        marker.getGeometry().translate(40, -40);
    }, 3500);

如果我传递了use_anauthenticated值,则会收到401响应:

let speech_to_text = new SpeechToTextV1({
  iam_apikey: STT_credentials.apikey,
  iam_url: STT_credentials.url
});

响应:

let speech_to_text = new SpeechToTextV1({
  iam_apikey: STT_credentials.apikey,
  iam_url: STT_credentials.url,
  use_unauthenticated: true
});

如果我查看错误文件:

Error! Code:401 Type: undefined Message: Unauthorized

我看到,如果没有用户名/密码参数,它将引发错误:

/Users/jward/Desktop/speech_lab_assets/STT/node_mod
ules/watson-developer-cloud/lib/base_service.js:73:13

如果watson-developer-cloud工具需要用户名/密码,我应该如何使用IAM?这是节点模块的问题,还是我做错了什么?

我正在使用watson-developer-cloud@2.42.0

1 个答案:

答案 0 :(得分:1)

将端点指定为url,而不是iam_url

这对我有用-

const  STTV1 = require('watson-developer-cloud/speech-to-text/v1');

let sttService = new STTV1({
  url: url,
  iam_apikey = apikey
});