#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    68
    Rep Power
    3

    WWW::Mechanize problems


    Hi, im using this code but im getting an error back.
    any ideas how to remove the error??

    Code:
    #!/usr/bin/perl 
    use WWW::Mechanize; 
    my $mech = WWW::Mechanize->new; 
    $url = 'https://demo04.service-now.com/'; 
    
    $mech->get($url); 
    $number = 1; 
    $mech->form_number($number);  
    $mech->field("user_name", "itil"); 
    $mech->filed("user_password", "itil");  
    $mech->click_button("not_important");

    ERROR:
    Code:
    Can't call method "value" on an undefined value at C:/Perl/lib/WWW/Mechanize.pm line 1403.
  2. #2
  3. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,259
    Rep Power
    1810
    The error likely occurs because the form you want isn't there. Try getting the page with perl and saving it to disk:

    Code:
    #!/usr/bin/perl
    use strict;
    use warnings;
    use LWP::UserAgent;
    
    my $ua = LWP::UserAgent->new; 
    my $r = $ua->get('https://demo04.service-now.com/');
    
     if ($r->is_success) {
     	open my $fh, ">", 'output.html' or die "Error: $!";
    	print $fh $r->decoded_content;
     } else {
         die $r->status_line;
     }
    The complete page is created by pulling a lot of different elements. There are at least two frames and four major javascript files. The javascript can run on the client side and build a lot of elements in the DOM that perl will never see, because perl just fetches the basic text and makes no effort to execute any of the code and create a dynamic page.

    In truth, it isn't impossible to post to that service through the HTML interface using perl, just difficult because they have deliberately obfuscated things. You would have to do a lot of investigative work to discover exactly what to post, and to where.

    And it isn't going to be worth the effort, because they could always change the interface and block you again.

    Which shouldn't be a big deal, because the site claims to have provided a SOAP interface for you, and has instructions on how to interface using perl.

    Perl_API_Configuration
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    68
    Rep Power
    3
    Hi,

    I found that SOAP interface before, but the problem is that i need to install ServiceNow perl module on my machine to be able to use that.

    Perl API


    i found ServiceNow perl module in this website but i have problems during the installation, i've tried on many devices but they refused to install that module.

    Any idea?

    thanks for your help.

    Originally Posted by keath
    The error likely occurs because the form you want isn't there. Try getting the page with perl and saving it to disk:

    Code:
    #!/usr/bin/perl
    use strict;
    use warnings;
    use LWP::UserAgent;
    
    my $ua = LWP::UserAgent->new; 
    my $r = $ua->get('https://demo04.service-now.com/');
    
     if ($r->is_success) {
     	open my $fh, ">", 'output.html' or die "Error: $!";
    	print $fh $r->decoded_content;
     } else {
         die $r->status_line;
     }
    The complete page is created by pulling a lot of different elements. There are at least two frames and four major javascript files. The javascript can run on the client side and build a lot of elements in the DOM that perl will never see, because perl just fetches the basic text and makes no effort to execute any of the code and create a dynamic page.

    In truth, it isn't impossible to post to that service through the HTML interface using perl, just difficult because they have deliberately obfuscated things. You would have to do a lot of investigative work to discover exactly what to post, and to where.

    And it isn't going to be worth the effort, because they could always change the interface and block you again.

    Which shouldn't be a big deal, because the site claims to have provided a SOAP interface for you, and has instructions on how to interface using perl.

    Perl_API_Configuration
  6. #4
  7. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,259
    Rep Power
    1810
    You'll have to be more specific about your errors.

    I just installed their module on Mac OS X 10.8. I saw an error during 'make test', but it was just because I didn't have MIME::Types installed yet. I installed that and the tests passed, so I did 'sudo make install' to finish.

    The I ran a test script from their website to create an incident and it failed because it couldn't find SOAP::Lite, so I installed that. Then the script ran without error and created an incident report.

    Code:
    #!/usr/bin/perl -w
    
    use ServiceNow;
    use ServiceNow::Configuration;
    
    my $CONFIG = ServiceNow::Configuration->new();
    
    $CONFIG->setSoapEndPoint("https://demo04.service-now.com/");
    $CONFIG->setUserName("admin");
    $CONFIG->setUserPassword("admin");
    
    my $SN = ServiceNow->new($CONFIG);
    
    my $number = $SN->createIncident({"short_description" => "this incident was created from the Perl API", "category" => "hardware"});
    
    print $number ."\n";
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    68
    Rep Power
    3
    I downloaded their module (ServiceNow) on my Windows machine, i extracted it and using strawberry perl i tried to run it with this command: perl Makefile.PL

    then the error i got is:
    Code:
    C:\Users\TsentisA\Documents>perl C:\Users\TsentisA\Documents\ServiceNow-Perl-API\ServiceNow-1.01\Makefile.PL
    Set up gcc environment - 4.4.7 20111023 (prerelease) [svn/rev.180339 - mingw-w64/oz]
    Argument "6.57_05" isn't numeric in numeric ge (>=) at C:\Users\TsentisA\Documents\ServiceNow-Perl-API\ServiceNow-1.01\Makefile.PL line 5.
    Could not open 'lib/ServiceNow.pm': No such file or directory at C:/Perl/lib/ExtUtils/MM_Unix.pm line 2658.
    I've already installed the following perl modules:
    SOAP::Lite (prerequisites http://soaplite.com/prereqs.html) 0.71 or later
    Crypt::SSLeay
    IO::Socket::SSL
    File::Basename
    MIME::Types
    MIME::Type
    MIME::Base64

    thanks

    Originally Posted by keath
    You'll have to be more specific about your errors.

    I just installed their module on Mac OS X 10.8. I saw an error during 'make test', but it was just because I didn't have MIME::Types installed yet. I installed that and the tests passed, so I did 'sudo make install' to finish.

    The I ran a test script from their website to create an incident and it failed because it couldn't find SOAP::Lite, so I installed that. Then the script ran without error and created an incident report.

    Code:
    #!/usr/bin/perl -w
    
    use ServiceNow;
    use ServiceNow::Configuration;
    
    my $CONFIG = ServiceNow::Configuration->new();
    
    $CONFIG->setSoapEndPoint("https://demo04.service-now.com/");
    $CONFIG->setUserName("admin");
    $CONFIG->setUserPassword("admin");
    
    my $SN = ServiceNow->new($CONFIG);
    
    my $number = $SN->createIncident({"short_description" => "this incident was created from the Perl API", "category" => "hardware"});
    
    print $number ."\n";
  10. #6
  11. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,259
    Rep Power
    1810
    Is ExtUtils::MakeMaker installed? That's where the version number is coming from.
  12. #7
  13. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,259
    Rep Power
    1810
    Here's your errors:
    Argument "6.57_05" isn't numeric in numeric ge (>=) at C:\Users\TsentisA\Documents\ServiceNow-Perl-API\ServiceNow-1.01\Makefile.PL line 5.
    Could not open 'lib/ServiceNow.pm': No such file or directory at C:/Perl/lib/ExtUtils/MM_Unix.pm line 2658.
    The first one is not fatal, so you can probably disregard it.

    The second one is a problem, and shows that you do have ExtUtils::MakeMaker installed, but it's using a Unix submodule which might be a problem for you.

    I don't use Windows, but the Makefile.pm might not be any good for you. The job can probably be done without. I think this is probably pure perl, so as long as the prerequisites are there you could probably just move the files manually into your lib.

    I've got to head out to work. If you can't get this working, I'll be back this afternoon.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    68
    Rep Power
    3
    No worries, thank you very much for your help so far.
    I will give it a try and i will you contact with you again!

    Originally Posted by keath
    Here's your errors:

    The first one is not fatal, so you can probably disregard it.

    The second one is a problem, and shows that you do have ExtUtils::MakeMaker installed, but it's using a Unix submodule which might be a problem for you.

    I don't use Windows, but the Makefile.pm might not be any good for you. The job can probably be done without. I think this is probably pure perl, so as long as the prerequisites are there you could probably just move the files manually into your lib.

    I've got to head out to work. If you can't get this working, I'll be back this afternoon.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    68
    Rep Power
    3
    Hi again, i wasn't able to move the files manually into my lib.
    Whenever you have time i will need some help!

    thanks

    Originally Posted by keath
    Here's your errors:

    The first one is not fatal, so you can probably disregard it.

    The second one is a problem, and shows that you do have ExtUtils::MakeMaker installed, but it's using a Unix submodule which might be a problem for you.

    I don't use Windows, but the Makefile.pm might not be any good for you. The job can probably be done without. I think this is probably pure perl, so as long as the prerequisites are there you could probably just move the files manually into your lib.

    I've got to head out to work. If you can't get this working, I'll be back this afternoon.
  18. #10
  19. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,259
    Rep Power
    1810
    I'm not a user of Strawberry Perl, but I think your @INC path has the following directories in it:

    Code:
    C:/strawberry/perl/site/lib
    C:/strawberry/perl/vendor/lib
    C:/strawberry/perl/lib
    Check your drive and confirm those exist. I'd probably use C:/strawberry/perl/vendor/lib, but site/lib would also be a good choice.

    All you should need to do is copy and paste a file and directory to one of those locations.

    Service Now prereqs:

    The ServiceNow Perl API requires Perl 5.8 (or later) with the following modules installed

    SOAP::Lite (prerequisites http://soaplite.com/prereqs.html) 0.71 or later
    Crypt::SSLeay
    IO::Socket::SSL
    File::Basename
    MIME::Types
    MIME::Type
    MIME::Base64
    If you have those, download and unzip the ServiceNow module

    Inside the unzipped directory, open the lib directory.



    That's all you need. Just copy the file and directory to the /vendor/lib directory. It's important to keep them both at the same directory level. In other words, don't put the ServiceNow.pm inside the ServiceNow directory.

    Then try running the test script I ran up above. It should work, or at least give a different error.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    68
    Rep Power
    3
    Hi, i did everything you told me and wasn't working but then i realized that i should copy the files to this directory C:\Perl\lib instead the one you gave me! The modules successfully installed, but still i have another error which i can't fix. when i run the script which creates an incident to that webpage, im getting this error:

    Code:
    500 Internal Server Error at C:/Perl/lib/ServiceNow/Connection.pm line 70.
    i used this code:

    Code:
    #!/usr/bin/perl -w
    
    use ServiceNow;
    use ServiceNow::Configuration;
    
    my $CONFIG = ServiceNow::Configuration->new();
    
    $CONFIG->setSoapEndPoint("https://demo.service-now.com/");
    $CONFIG->setUserName("admin");
    $CONFIG->setUserPassword("admin");
    
    my $SN = ServiceNow->new($CONFIG);
    
    my $number = $SN->createIncident({"short_description" => "this incident was created from the Perl API", "category" => "hardware"});
    
    print $number ."\n";
    and since i run that script im can't access this webpage "https://demo.service-now.com/" not even from my browser.

    Any idea?

    Originally Posted by keath
    I'm not a user of Strawberry Perl, but I think your @INC path has the following directories in it:

    Code:
    C:/strawberry/perl/site/lib
    C:/strawberry/perl/vendor/lib
    C:/strawberry/perl/lib
    Check your drive and confirm those exist. I'd probably use C:/strawberry/perl/vendor/lib, but site/lib would also be a good choice.

    All you should need to do is copy and paste a file and directory to one of those locations.

    Service Now prereqs:



    If you have those, download and unzip the ServiceNow module

    Inside the unzipped directory, open the lib directory.



    That's all you need. Just copy the file and directory to the /vendor/lib directory. It's important to keep them both at the same directory level. In other words, don't put the ServiceNow.pm inside the ServiceNow directory.

    Then try running the test script I ran up above. It should work, or at least give a different error.
    Last edited by andreas.london; August 17th, 2012 at 05:13 AM.
  22. #12
  23. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,259
    Rep Power
    1810
    Yeah, those demo instances the ServiceNow creates only last for a short time. You'll have to go to the web page and start a new one, then take note of the url because it may be demo01 - demo12 or whatever. Change the url in the script to match the new demo and it should work.

    Looks like demo04 is currently working.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    68
    Rep Power
    3
    WOW, it is working very well! Thank you very very much for your help. I owe you!

    Originally Posted by keath
    Yeah, those demo instances the ServiceNow creates only last for a short time. You'll have to go to the web page and start a new one, then take note of the url because it may be demo01 - demo12 or whatever. Change the url in the script to match the new demo and it should work.

    Looks like demo04 is currently working.

IMN logo majestic logo threadwatch logo seochat tools logo