简体   繁体   English

具有“ LWP :: UserAgent”错误的Perl“ HTTP :: cookies”“:看起来不像Netscape cookie文件”

[英]Perl “HTTP::cookies”“ with ”LWP::UserAgent“ error: ”does not look like a Netscape cookies file"

I'm trying to do the equivalent of curl --cookie cookies.txt "https://foo.example.org/bar" in a Perl script. 我正在尝试在Perl脚本中执行curl --cookie cookies.txt "https://foo.example.org/bar"的等效操作。 I have a cookies file that I believe is in Netscape format (tab delimited) that works fine with curl . 我有一个cookie文件,我相信它是Netscape格式(制表符分隔),可以与curl配合使用。 HTTP::cookies complains: HTTP::cookies抱怨:

cookies.txt does not look like a Netscape cookies file at /System/Library/Perl/Extras/5.10.0/HTTP/Cookies/netscape.pm line 21, line 1. cookies.txt在/System/Library/Perl/Extras/5.10.0/HTTP/Cookies/netscape.pm第21行,第1行中看起来像不是Netscape cookie文件。

My script is just a stub for testing: 我的脚本只是测试的存根:

#!/usr/bin/perl -w

use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
use HTTP::Cookies::Netscape;
my $cookie_jar = HTTP::Cookies::Netscape->new
                  ( 'file' => 'cookies.txt', );  
my $url = 'http://www.google.com/';
my $response = $ua->get( $url );
print "Return: $response->status_line\n";

The cookies.txt file actually starts with a comment: cookies.txt文件实际上以注释开头:

# This content may be pasted into a cookies.txt file and used by wget

But I tried deleting the comment and got the same exact error. 但是我尝试删除评论,并得到相同的确切错误。 The cookies.txt file has Unix style line endings. cookies.txt文件具有Unix样式行的结尾。

Arg! 精氨酸!

Turns out that, while curl is happy with the file, the HTTP::Cookes::Netscape module wants the first line to be 事实证明,虽然curl对文件满意,但HTTP::Cookes::Netscape模块希望第一行是

# Netscape HTTP Cookie File

I added that, and now it seems happy. 我加了,现在看来很高兴。

(I found the module source code and searched for the error message.) (我找到了模块源代码并搜索了错误消息。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM