+ -
当前位置:首页 → 问答吧 → Can't use string ("[email protected]") as a HASH ref

Can't use string ("[email protected]") as a HASH ref

时间:2011-04-07

来源:互联网

client(tcl实现)使用xmlrpc和server(perl实现)通信时收到如下错误,请哪位帮忙看一下什么意思?我只负责client的实现,不懂perl。谢过了

Can't use string ("[email protected]") as a HASH ref while "strict refs" in use
at Bugzilla/WebService/User.pm line 45.

client代码:
  1. package require XMLRPC

  2. XMLRPC::create "User.login" -proxy http://bugzilla/bugzilla/tr_xmlrpc.cgi \
  3.         -params {login string password string remember boolean}

  4. set result [User.login [email protected] 123456 0]
  5. puts $result
复制代码
User.pm代码:
  1. # -*- Mode: perl; indent-tabs-mode: nil -*-
  2. #
  3. # The contents of this file are subject to the Mozilla Public
  4. # License Version 1.1 (the "License"); you may not use this file
  5. # except in compliance with the License. You may obtain a copy of
  6. # the License at http://www.mozilla.org/MPL/
  7. #
  8. # Software distributed under the License is distributed on an "AS
  9. # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10. # implied. See the License for the specific language governing
  11. # rights and limitations under the License.
  12. #
  13. # The Original Code is the Bugzilla Bug Tracking System.
  14. #
  15. # Contributor(s): Marc Schumann <[email protected]>
  16. #                 Max Kanat-Alexander <[email protected]>
  17. #                 Mads Bondo Dydensborg <[email protected]>
  18. #                 Noura Elhawary <[email protected]>

  19. package Bugzilla::WebService::User;

  20. use strict;
  21. use base qw(Bugzilla::WebService);

  22. use Bugzilla;
  23. use Bugzilla::Constants;
  24. use Bugzilla::Error;
  25. use Bugzilla::User;
  26. use Bugzilla::Util qw(trim);
  27. use Bugzilla::Token;
  28. use Bugzilla::WebService::Util qw(filter validate);

  29. # Don't need auth to login
  30. use constant LOGIN_EXEMPT => {
  31.     login => 1,
  32.     offer_account_by_email => 1,
  33. };

  34. ##############
  35. # User Login #
  36. ##############

  37. sub login {
  38.     my ($self, $params) = @_;
  39.     my $remember = $params->{remember};

  40.     # Username and password params are required
  41.     foreach my $param ("login", "password") {
  42.         defined $params->{$param}
  43.             || ThrowCodeError('param_required', { param => $param });
  44.     }

  45.     # Convert $remember from a boolean 0/1 value to a CGI-compatible one.
  46.     if (defined($remember)) {
  47.         $remember = $remember? 'on': '';
  48.     }
  49.     else {
  50.         # Use Bugzilla's default if $remember is not supplied.
  51.         $remember =
  52.             Bugzilla->params->{'rememberlogin'} eq 'defaulton'? 'on': '';
  53.     }

  54.     # Make sure the CGI user info class works if necessary.
  55.     my $cgi = Bugzilla->cgi;
  56.     $cgi->param('Bugzilla_login', $params->{login});
  57.     $cgi->param('Bugzilla_password', $params->{password});
  58.     $cgi->param('Bugzilla_remember', $remember);

  59.     Bugzilla->login;
  60.     return { id => $self->type('int', Bugzilla->user->id) };
  61. }

  62. sub logout {
  63.     my $self = shift;
  64.     Bugzilla->logout;
  65.     return undef;
  66. }
复制代码

作者: rossini23   发布时间: 2011-04-07

你调用的时候出错了吧?上面的看不懂不过可以猜下

-param {login string password string remember boolean}

传入参数的时候是不是应该是 'login' User.login ‘password' [email protected] ’remember‘ 123456 ‘boolean’ 0 组成的一个 hashref
下面 login 函数需要一个 hashref 参数,出错原因是你传入的不是 hashref

作者: zhlong8   发布时间: 2011-04-07

本帖最后由 rossini23 于 2011-04-07 11:11 编辑


QUOTE:
你调用的时候出错了吧?上面的看不懂不过可以猜下

-param {login string password string remember bool ...
zhlong8 发表于 2011-04-07 10:59



谢谢。试了一下,还是出错。这次应该是本地给出的错误。之前的错误我用wireshark抓包看到的,是server端返回的。
D:\>tclsh testopia.tcl
wrong # args: should be "User.login login password remember"


我也怀疑是传参可能跟server端不大一样,但是tcl的传参确实是这样的,怎么传都还是string。

User.login是testopia提供的API,具体描述见下面的链接:
http://landfill.bugzilla.org/tes ... ebService/User.html

作者: rossini23   发布时间: 2011-04-07

那我就不懂鸟,反正提示错误的意思是传入 login 的参数应该是 hashref 却传入了 [email protected]

作者: zhlong8   发布时间: 2011-04-07

回复 zhlong8


   我又尝试了一下,发现确实是传参的问题。下面的代码就ok了,谢谢了。
  1. package require XMLRPC

  2. ::rpcvar::typedef {
  3.         login string
  4.         password string
  5.         remember boolean       
  6. } login

  7. XMLRPC::create "User.login" -proxy http://bugzilla/bugzilla/tr_xmlrpc.cgi \
  8.         -params [list login login]

  9. set result [User.login [list login [email protected] password 123456 remember 1]]
  10. puts $result
复制代码

作者: rossini23   发布时间: 2011-04-07

那个文档没说调用方式啊,是不是 User.login -login [email protected] -password xxx -rember 1

作者: zhlong8   发布时间: 2011-04-07