无法使用代理呼叫Watson语言翻译器

时间:2019-07-16 16:37:06

标签: nginx ibm-watson nginx-location watson-assistant

当我通过公共网络致电Watson语言翻译服务时,它的响应没有错误。同时,它无法通过我的专用网络获取回复正文

我正在使用NGINX的负载均衡器,并在配置中为其配置了proxy_http。

错误是

{错误:未收到响应。错误内容为HTTP ClientRequest对象     在formatError(root \ node_modules \ ibm-cloud-sdk-core \ lib \ requestwrapper.js:115:17)     在D:\ Rafiki Project \ production build \ Rafiki Production Files 1 \ ecobot-orchestrator-master_23_9-orch_persistency_fixes \ node_modules \ ibm-cloud-sdk-core \ lib \ requestwrapper.js:265:19     在process._tickCallback(internal / process / next_tick.js:68:7)

var languageTranslator = new LanguageTranslatorV2({
  username:'8******************',
  password:'*************',
  url: 'https://gateway.watsonplatform.net/language-translator/api/',
  version: '2017-05-26'
});

function translateToWSPLan(req, res, callback){
  console.log("the request for translation is::");
  console.log(JSON.stringify(req));
  console.log("======================");
  languageTranslator.identify(req.body.identifyParams, function(err, data){
    if(err){
      console.log('=================error==========');
      console.log(err);
      console.log('=================================');
      var errorLog = {name: err.name, message: err.message};
      callback(errorLog);
    }else {

    }
})

1 个答案:

答案 0 :(得分:0)

请参阅在Watson的Node.js SDK上引发的此问题-https://github.com/watson-developer-cloud/node-sdk/issues/900#issuecomment-509257669

要启用代理路由,请将代理设置添加到构造函数中

public class CustomAdapter extends BaseAdapter {

    Context context;
    //data container
    ArrayList<Student> list;
    LayoutInflater inflater;

    //contructor


    public CustomAdapter(Context context, ArrayList<Student> list) {
        this.context = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    public void refreshList(ArrayList<Student> list){
        this.list = list;
        notifyDataSetChanged()
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.custom_layout, parent, false);
            holder.iv = (ImageView) convertView.findViewById(R.id.imageView);
            holder.lname = (TextView) convertView.findViewById(R.id.textLastname);
            holder.fname= (TextView) convertView.findViewById(R.id.textFirstname);
            holder.course = (TextView) convertView.findViewById(R.id.textCourse);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }

        //inflate
        holder.iv.setImageURI(list.get(position).getUriImage());
        holder.lname.setText(list.get(position).getStudlname());
        holder.fname.setText(list.get(position).getStudfname());
        holder.course.setText(list.get(position).getStudcourse());

        return convertView;
    }

    //creating a static class
    static class ViewHolder{
        ImageView iv;
        TextView lname, fname,course;
    }
}

如果您查看此问题,则说明访问IAM令牌存在问题,当存在代理时,该问题不起作用,但是由于您似乎正在使用用户名/密码组合,因此应该可以。直到所有现有的Watson服务的IAM凭证被云边界样式凭证挂起和取代为止。