views:

363

answers:

1

I'm writing simple program which has to change some data on Polish auction site.

One of the steps involves loading edit page, changing one value, and submitting it.

Sample page can be viewed here: http://depesz.com/various/new_item.php.html - this is just static copy of such edit page.

Relevant part of my perl code:

$agent->form_number( 1 );
$agent->submit();
$agent->form_number( 1 );

my $q = $agent->current_form()->find_input( 'scheme_id' );
$agent->field('scheme_id', '1025');
# $agent->field('description', encode('utf-8', $agent->value("description")));
# $agent->field('location', encode('utf-8', $agent->value("location")));
# $agent->field('transport_shipment_description', encode('utf-8', $agent->value("transport_shipment_description")));
$agent->submit;
print $agent->response->decoded_content . "\n";

After first submit I get the page I showed. Then I change value in scheme_id field to 1025, and submit the form.

Afterward I get:

HTTP::Message content must be bytes at /usr/local/share/perl/5.8.8/HTTP/Request/Common.pm line 91

I tried to recode values on text fields on the form - hence the agent->field(... encode) lines, but it didn't help.

At the moment I have no idea what on the form can make WWW::Mechanize fail in such way, but I clearly cannot fix in on my own.

Is there any way to debug this situation? Or perhaps I should do something differently?

+1  A: 

Make sure your LWP and WWW-Mechanize modules are fully up to date. LWP fixed a number of encoding problems in late 2008, if I recall correctly.

Frakkle
Note: I'm not sure this will entirely solve the problem, but I am not sure what else to check. I just know when I ran into that error in the past it was an encoding problem. Hope it helps.
Frakkle
Unfortunately both are up to date:=> modver LWPVersion 5.825=> modver WWW::MechanizeVersion 1.54
depesz
Have you tried updating again? WWW::Mechanize 1.56 changed the way it handles encodings: "For a while, Mech used HTTP::Response::Encoding to try to suss outthe proper encoding of the page it receives. Now, it letsLWP::UserAgent do the work, and no longer requiresHTTP::Response::Encoding."
cjm