使用 Perl 添加 Google 日历条目时出现 XML 错误
有一个包含日期和名称的数组,我想使用以下子例程将事件添加到谷歌日历:
use Net::Google::Calendar;
use Date::Manip;
use Date::Calc qw(Add_Delta_Days);
my $username #removed for stackoverflow
my $password #removed for stackoverflow
my $cal = Net::Google::Calendar->new;
my $from = new Date::Manip::Date;
my $to = new Date::Manip::Date;
my @f;
my @t;
my $year;
my $month;
my $day;
$cal->login($username, $password) or $MESSAGERED = "Google Calendar login failed.";
my $entry;
#[0] name
#[1] from
#[2] to
#[3] hid
for my $i (0 .. $#ALL_HOLIDAYS) {
$from->parse($ALL_HOLIDAYS[$i][1]);
$to->parse($ALL_HOLIDAYS[$i][2]);
@f = $from->value();
@t = $to->value();
# a day added in line with our "last day of absence"
($year, $month, $day) = Add_Delta_Days($t[0], $t[1], $t[2], 1);
$entry = Net::Google::Calendar::Entry->new() or die " 518 ++++++++++ ";
$entry->when(DateTime->new(year => $f[0], month => $f[1], day => $f[2]), DateTime->new(year => $year, month => $month, day => $day)) or die " 519 ++++++++++ ";
$entry->title($ALL_HOLIDAYS[$i][0]) or die " 520 ++++++++++ ";
$entry->content("Holiday") or die " 521 ++++++++++ ";
$entry->transparency('transparent') or die " 522++++++++++ ";
$entry->status('confirmed') or die " 523 ++++++++++ ";
if ($cal->add_entry($entry)) {
&mark_entry_as_googd($ALL_HOLIDAYS[$i][3]);
} else {
$MESSAGEORANGE = "Unable to submit entry for ".$ALL_HOLIDAYS[$i][0]
}
}
$MESSAGEGREEN = "Google Calendar populated";
print $MESSAGERED.$MESSAGEGREEN.$MESSAGEORANGE;
事情是,一旦我取下这个脚本并在我的控制台(osx)中运行它,它就可以正常运行,事件被添加到谷歌日历。 如果它在 debian 服务器上执行,则会收到以下错误,这就是我问这个问题的原因:
没有命名空间匹配前缀:xmlns at /usr/local/share/perl/5.10.1/XML/XPath/Node /Element.pm 第 261 行。
CPAN 在两台计算机上报告相同的情况,即 Net::Google::Calendar 及其依赖项均已安装。这些die
都不起作用,总是出现同样的错误。我意识到这个模块是 alpha,但为什么会出现差异?
Having an array with dates and names I want to add events to a google calendar with the following subroutine:
use Net::Google::Calendar;
use Date::Manip;
use Date::Calc qw(Add_Delta_Days);
my $username #removed for stackoverflow
my $password #removed for stackoverflow
my $cal = Net::Google::Calendar->new;
my $from = new Date::Manip::Date;
my $to = new Date::Manip::Date;
my @f;
my @t;
my $year;
my $month;
my $day;
$cal->login($username, $password) or $MESSAGERED = "Google Calendar login failed.";
my $entry;
#[0] name
#[1] from
#[2] to
#[3] hid
for my $i (0 .. $#ALL_HOLIDAYS) {
$from->parse($ALL_HOLIDAYS[$i][1]);
$to->parse($ALL_HOLIDAYS[$i][2]);
@f = $from->value();
@t = $to->value();
# a day added in line with our "last day of absence"
($year, $month, $day) = Add_Delta_Days($t[0], $t[1], $t[2], 1);
$entry = Net::Google::Calendar::Entry->new() or die " 518 ++++++++++ ";
$entry->when(DateTime->new(year => $f[0], month => $f[1], day => $f[2]), DateTime->new(year => $year, month => $month, day => $day)) or die " 519 ++++++++++ ";
$entry->title($ALL_HOLIDAYS[$i][0]) or die " 520 ++++++++++ ";
$entry->content("Holiday") or die " 521 ++++++++++ ";
$entry->transparency('transparent') or die " 522++++++++++ ";
$entry->status('confirmed') or die " 523 ++++++++++ ";
if ($cal->add_entry($entry)) {
&mark_entry_as_googd($ALL_HOLIDAYS[$i][3]);
} else {
$MESSAGEORANGE = "Unable to submit entry for ".$ALL_HOLIDAYS[$i][0]
}
}
$MESSAGEGREEN = "Google Calendar populated";
print $MESSAGERED.$MESSAGEGREEN.$MESSAGEORANGE;
Thing is as soon as I take this script off and run it in my console (osx) it runs all right, the events are added to google calendar.
If it executes on the debian server the following error, the reason for me asking this question, is received:
No namespace matches prefix: xmlns at /usr/local/share/perl/5.10.1/XML/XPath/Node/Element.pm line 261.
CPAN reports the same thing on both machines, that both Net::Google::Calendar and its dependencies are installed. None of those die
s work either, it's always that same error. I realise this module is alpha but still, why the discrepancy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是 Google 模块没有为 xml 响应中的条目设置正确的命名空间。它回退到默认名称空间(什么也没有)。条目可能看起来像<一些名称:标签>如果不将命名空间设置为某个名称,应用程序将无法检索该数据。默认值为“xmls”,因此默认名称空间正在寻找诸如 << 的标签。 xmls:标签>并且找不到任何。 (每个安装的默认命名空间可能有所不同 - 还要检查 xmlib 版本,我记得默认值最近已更改为“xmlns”以强制使用命名空间)。
如果没有看到 xml 响应,就很难正确回答。有没有办法可以捕获或转储响应到文件。看到标题后,您就可以看到问题出在哪里。如果 xml 响应正确,则模块不会设置名称空间,这将是其最终的错误。
带有 xmlns 的命名空间示例
My guess is the Google module is not setting the correct namespace for the entry in the xml response. Its falling back to the default namespace (nothing). Entries may look like < somename:tag > without setting the namespace to somename, the app cannot retrieve that data. The default is 'xmls', so the default namespace is looking for tags like < xmls:tag > and cannot find any. (The default namespace may be different on each installation - check the xmlib versions as well, I recall the default was changed to 'xmlns' recently to force namespace usage).
Without seeing the xml response, its hard to answer correctly. Is there a way you can capture or dump the response to a file. Once you see the header, you can see where the problem is. If the xml response is correct, then the module isnt setting the namespace, which would be bug on their end.
Example of namespaces with xmlns