Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

posting a message with LWP fails on Windows 2016

by fredho (Novice)
on Dec 07, 2017 at 11:23 UTC ( #1205081=perlquestion: print w/replies, xml ) Need Help??
fredho has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I'm facing a weird issue with a script that posts messages on Zendesk. The script has been working for years on Windows 2003 and doesn't on Windows 2016. And yet, the http return code is 200, and no error is returned.
I've checked that there is no network or firewall issues by sending a simple post through curl.
I'm wondering how I can add traces to get clues about what's going wrong.
Here is a test script that fails on W2016 and works on W2003.
Thank you

#!/usr/bin/perl use strict; use LWP::UserAgent; use LWP::Debug qw(+); use JSON; # Zendesk my $netloc = ''; my $realm = 'Web Password'; my $uname = ''; my $pass = 'xxxxxxxxxxx'; my $Server = $ARGV[0]; my $TicketID = "1234"; Comment_Zendesk($TicketID,$Server); exit; sub Comment_Zendesk { my($ZID,$ZServer) = @_; # Create a user agent, and specify the credentials and header of y +our API requests my $ua = LWP::UserAgent->new(); $ua->credentials($netloc, $realm, $uname, $pass); $ua->default_header('Content-Type' => 'application/json'); # Endpoint URL my $url = ''.$ZID.'.json'; # Call the API my $body = "Message posted from $ZServer"; my $json = JSON->new->allow_nonref; my $json_body = $json->encode($body); my $data = '{"ticket": { "comment": {"body": ' . $json_body . ' } +} }'; my $response = $ua->put($url, Content => $data); # Check for HTTP error codes if (! $response->is_success) { die 'http status: ' . $response->code . ' ' . $response->mess +age; } print "\n--- response->code ---\n" . $response->code . "\n"; print "\n--- response->message ---\n" . $response->message. "\n"; print "\n--- response->content ---\n" . $response->content() . "\n +"; print "\n--- response->header ---\n" . $response->header("WWW-Aut +henticate"); }

Replies are listed 'Best First'.
Re: posting a message with LWP fails on Windows 2016
by hippo (Canon) on Dec 07, 2017 at 12:19 UTC

    Since you haven't mentioned it I thought I should point out that there are not one but two modules on CPAN which interface with the Zendesk API. You can take your pick from

    Perhaps using one of those will be less hassle in both the short and long term than rolling your own?

Re: posting a message with LWP fails on Windows 2016
by virtualsue (Vicar) on Dec 07, 2017 at 11:57 UTC
    You haven't said how it doesn't work, so it's difficult to be very helpful. Either run it through the Perl debugger via "perl -d yourscript" or put in some print statements. The modules Data::Dumper or Data::Printer are useful for inspecting your variables. Data::Dumper is core, so you shouldn't need to install it. Good luck, please follow up with more info or questions.
Re: posting a message with LWP fails on Windows 2016
by fredho (Novice) on Dec 07, 2017 at 12:48 UTC

    Hi virtualsue, you're right, I realize it was not clear in my original post. What I mean by "it does not work" is that no message is posted in the Zendesk to which I want to add a comment. The batch ends with no error. Messages returned by the post are similar whether the post succeeds or not (http 200 OK).
    Thank you for pointing these 2 modules out hippo, I'll see if I can turn around the issue using them.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1205081]
Approved by johngg
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2018-07-20 09:17 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (427 votes). Check out past polls.