免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5275 | 回复: 5
打印 上一主题 下一主题

Can't use string ("abc@abc.com") as a HASH ref [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-04-07 10:18 |只看该作者 |倒序浏览
client(tcl实现)使用xmlrpc和server(perl实现)通信时收到如下错误,请哪位帮忙看一下什么意思?我只负责client的实现,不懂perl。谢过了

Can't use string ("abc@abc.com") 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 abc@abc.com 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 <wurblzap@gmail.com>
  16. #                 Max Kanat-Alexander <mkanat@bugzilla.org>
  17. #                 Mads Bondo Dydensborg <mbd@dbc.dk>
  18. #                 Noura Elhawary <nelhawar@redhat.com>

  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. }
复制代码

论坛徽章:
46
15-16赛季CBA联赛之四川
日期:2018-03-27 11:59:132015年亚洲杯之沙特阿拉伯
日期:2015-04-11 17:31:45天蝎座
日期:2015-03-25 16:56:49双鱼座
日期:2015-03-25 16:56:30摩羯座
日期:2015-03-25 16:56:09巳蛇
日期:2015-03-25 16:55:30卯兔
日期:2015-03-25 16:54:29子鼠
日期:2015-03-25 16:53:59申猴
日期:2015-03-25 16:53:29寅虎
日期:2015-03-25 16:52:29羊年新春福章
日期:2015-03-25 16:51:212015亚冠之布里斯班狮吼
日期:2015-07-13 10:44:56
2 [报告]
发表于 2011-04-07 10:59 |只看该作者
你调用的时候出错了吧?上面的看不懂不过可以猜下

-param {login string password string remember boolean}

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

论坛徽章:
0
3 [报告]
发表于 2011-04-07 11:09 |只看该作者
本帖最后由 rossini23 于 2011-04-07 11:11 编辑
你调用的时候出错了吧?上面的看不懂不过可以猜下

-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

论坛徽章:
46
15-16赛季CBA联赛之四川
日期:2018-03-27 11:59:132015年亚洲杯之沙特阿拉伯
日期:2015-04-11 17:31:45天蝎座
日期:2015-03-25 16:56:49双鱼座
日期:2015-03-25 16:56:30摩羯座
日期:2015-03-25 16:56:09巳蛇
日期:2015-03-25 16:55:30卯兔
日期:2015-03-25 16:54:29子鼠
日期:2015-03-25 16:53:59申猴
日期:2015-03-25 16:53:29寅虎
日期:2015-03-25 16:52:29羊年新春福章
日期:2015-03-25 16:51:212015亚冠之布里斯班狮吼
日期:2015-07-13 10:44:56
4 [报告]
发表于 2011-04-07 11:11 |只看该作者
那我就不懂鸟,反正提示错误的意思是传入 login 的参数应该是 hashref 却传入了 abc@abc.com

论坛徽章:
0
5 [报告]
发表于 2011-04-07 11:16 |只看该作者
回复 4# 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 abc@abc.com password 123456 remember 1]]
  10. puts $result
复制代码

论坛徽章:
46
15-16赛季CBA联赛之四川
日期:2018-03-27 11:59:132015年亚洲杯之沙特阿拉伯
日期:2015-04-11 17:31:45天蝎座
日期:2015-03-25 16:56:49双鱼座
日期:2015-03-25 16:56:30摩羯座
日期:2015-03-25 16:56:09巳蛇
日期:2015-03-25 16:55:30卯兔
日期:2015-03-25 16:54:29子鼠
日期:2015-03-25 16:53:59申猴
日期:2015-03-25 16:53:29寅虎
日期:2015-03-25 16:52:29羊年新春福章
日期:2015-03-25 16:51:212015亚冠之布里斯班狮吼
日期:2015-07-13 10:44:56
6 [报告]
发表于 2011-04-07 11:17 |只看该作者
那个文档没说调用方式啊,是不是 User.login -login abc@abc.com -password xxx -rember 1
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP