Craft CMS 3 - Internal Server Error on certain pages - http-status-code-500

After upgrading to Craft 3 from 2, I'm getting a 500 Internal Server Error on a select few pages. For example:
/reports (Doesn't work)
/reports/slug (Works)
/publications (Doesn't work)
/publications/slug (Works)
For some reason it's not the same for all paths. /media works just fine. This is what shows up in my logs but I have no idea what it means. Also, the error screen I get is a Craft-styled page.
2020-09-25 00:37:46 [-][1][80b3e94259710a336582ea71cac98d1a][info][application] $_GET = [
'p' => 'publications'
]
$_POST = []
$_FILES = []
$_COOKIE = [
'CraftSessionId' => '80b3e94259710a336582ea71cac98d1a'
'1031b8c41dfff97a311a7ac99863bdc5_identity' => 'f108309014ae583a6eb6ce545f6acdd1c25222a18bee9c382e0050742d3cd949a:2:{i:0;s:41:\"1031b8c41dfff97a311a7ac99863bdc5_identity\";i:1;s:246:\"[\"1\",\"[\\\"xS6JjF6hHAbX59SK5XGpi5Ktmw-FTf-phJhV7uix7aalULuGzl308wNhAVNTGY2dPm7xXOk6dLOgaR2NbBXEqhhZFF649LoNhLnu\\\",null,\\\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36\\\"]\",1209600]\";}'
'1031b8c41dfff97a311a7ac99863bdc5_username' => '9a33d470ce6b2e033bab618b31164d34798869ae07d8c7515cc445de0603e560a:2:{i:0;s:41:\"1031b8c41dfff97a311a7ac99863bdc5_username\";i:1;s:25:\"mollie#email.com\";}'
'CRAFT_CSRF_TOKEN' => '•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••'
]
$_SESSION = [
'bd62416aa8538ede709019a5e113eea5__flash' => []
'1031b8c41dfff97a311a7ac99863bdc5__token' => '••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••'
'1031b8c41dfff97a311a7ac99863bdc5__id' => '1'
'1031b8c41dfff97a311a7ac99863bdc5__expire' => 1600997866
'bd62416aa8538ede709019a5e113eea5__auth_access' => [
0 => 'editStructure:5'
1 => 'editStructure:11'
2 => 'editStructure:9'
3 => 'editStructure:6'
4 => 'editStructure:8'
]
]
$_SERVER = [
'TMP' => '/srv/users/serverpilot/tmp/water-institute'
'TEMP' => '/srv/users/serverpilot/tmp/water-institute'
'TMPDIR' => '/srv/users/serverpilot/tmp/water-institute'
'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
'USER' => 'serverpilot'
'HOME' => '/srv/users/serverpilot'
'SCRIPT_NAME' => '/index.php'
'REQUEST_URI' => '/publications'
'QUERY_STRING' => 'p=publications'
'REQUEST_METHOD' => 'GET'
'SERVER_PROTOCOL' => 'HTTP/1.0'
'GATEWAY_INTERFACE' => 'CGI/1.1'
'REDIRECT_QUERY_STRING' => 'p=publications'
'REDIRECT_URL' => '/publications'
'REMOTE_PORT' => '38390'
'SCRIPT_FILENAME' => '/srv/users/serverpilot/apps/water-institute/public/index.php'
'SERVER_ADMIN' => 'webmaster#'
'CONTEXT_DOCUMENT_ROOT' => '/srv/users/serverpilot/apps/water-institute/public'
'CONTEXT_PREFIX' => ''
'REQUEST_SCHEME' => 'https'
'DOCUMENT_ROOT' => '/srv/users/serverpilot/apps/water-institute/public'
'REMOTE_ADDR' => '209.555.242.105'
'SERVER_PORT' => '443'
'SERVER_ADDR' => '127.0.0.1'
'SERVER_NAME' => 'dev.thewaterinstitute.org'
'SERVER_SOFTWARE' => 'Apache/2.4.46 (Unix) OpenSSL/1.0.2g'
'SERVER_SIGNATURE' => ''
'LD_LIBRARY_PATH' => '/opt/sp/apache/lib:/opt/sp/apache/lib'
'HTTP_COOKIE' => 'CraftSessionId=80b3e94259710a336582ea71cac98d1a; 1031b8c41dfff97a311a7ac99863bdc5_identity=f108309014ae583a6eb6ce545f6acdd1c25222a18bee9c382e0050742d3cd949a%3A2%3A%7Bi%3A0%3Bs%3A41%3A%221031b8c41dfff97a311a7ac99863bdc5_identity%22%3Bi%3A1%3Bs%3A246%3A%22%5B%221%22%2C%22%5B%5C%22xS6JjF6hHAbX59SK5XGpi5Ktmw-FTf-phJhV7uix7aalULuGzl308wNhAVNTGY2dPm7xXOk6dLOgaR2NbBXEqhhZFF649LoNhLnu%5C%22%2Cnull%2C%5C%22Mozilla%2F5.0+%28Windows+NT+10.0%3B+Win64%3B+x64%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F85.0.4183.83+Safari%2F537.36%5C%22%5D%22%2C1209600%5D%22%3B%7D; 1031b8c41dfff97a311a7ac99863bdc5_username=9a33d470ce6b2e033bab618b31164d34798869ae07d8c7515cc445de0603e560a%3A2%3A%7Bi%3A0%3Bs%3A41%3A%221031b8c41dfff97a311a7ac99863bdc5_username%22%3Bi%3A1%3Bs%3A25%3A%22mollie%40email.com%22%3B%7D; CRAFT_CSRF_TOKEN=25773457aeb176b611944eb8242d07ca89d6db0513942ffa87741e60f6789b13a%3A2%3A%7Bi%3A0%3Bs%3A16%3A%22CRAFT_CSRF_TOKEN%22%3Bi%3A1%3Bs%3A208%3A%226WM7NPL9Vbakyko4DJ-9pHHorwTsXXoGGZTOowAj%7Cedd0c62c7d374da3e339e8d4cc1fa8143778f59331f0d207580bec8e76567a666WM7NPL9Vbakyko4DJ-9pHHorwTsXXoGGZTOowAj%7C1%7C%242y%2413%24SPzKwYvJwBZgGjgrnHip6u2WVgGOtTJhn4Rix9UqItYl1o%2FMzgRZK%22%3B%7D'
'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.9,la;q=0.8'
'HTTP_ACCEPT_ENCODING' => 'gzip, deflate, br'
'HTTP_SEC_FETCH_DEST' => 'document'
'HTTP_SEC_FETCH_USER' => '?1'
'HTTP_SEC_FETCH_MODE' => 'navigate'
'HTTP_SEC_FETCH_SITE' => 'none'
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'
'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36'
'HTTP_UPGRADE_INSECURE_REQUESTS' => '1'
'HTTP_CONNECTION' => 'close'
'HTTP_X_FORWARDED_PROTO' => 'https'
'HTTP_X_FORWARDED_SSL' => 'on'
'HTTP_X_FORWARDED_FOR' => '209.555.242.105'
'HTTP_HOST' => 'dev.mydomain.org'
'SCRIPT_URI' => 'https://dev.mydomain.org/publications'
'SCRIPT_URL' => '/publications'
'HTTPS' => 'on'
'REDIRECT_STATUS' => '200'
'REDIRECT_SCRIPT_URI' => 'https://dev.mydomain.org/publications'
'REDIRECT_SCRIPT_URL' => '/publications'
'REDIRECT_HTTPS' => 'on'
'FCGI_ROLE' => 'RESPONDER'
'PHP_SELF' => '/index.php'
'REQUEST_TIME_FLOAT' => 1600994266.1376
'REQUEST_TIME' => 1600994266
'argv' => [
0 => 'p=publications'
]
'argc' => 1
'ENVIRONMENT' => 'dev'
'SECURITY_KEY' => '••••••••••••••••'
'DB_DRIVER' => 'mysql'
'DB_SERVER' => 'localhost'
'DB_USER' => 'e39b766ddf0a'
'DB_PASSWORD' => '••••••••••••••••'
'DB_DATABASE' => 'water-institute'
'DB_SCHEMA' => 'public'
'DB_TABLE_PREFIX' => 'craft'
'DB_PORT' => ''
'ROOT_URL' => 'https://dev.mydomain.org'
]

Related

Sending with method POST comes in as method GET with ZF3 Http Client

I'm trying to make a POST request with ZF3 Http Client but it comes in as a GET request all the time. I checked the manuals on the zend framework website but I can't find what I'm doing wrong. Probably it will be something small.
My simple script from the client side is:
$request = new Client();
$request->setUri('http://keuringapp.localhost/inspections/pdf/66');
$request->setMethod(Request::METHOD_POST);
$response = $request->send();
die($response->getBody());
on the server side I have this:
$test = $this->getRequest();
print_r($test);exit();
``
and it give met this result:
Zend\Http\PhpEnvironment\Request Object
(
[baseUrl:protected] =>
[basePath:protected] =>
[requestUri:protected] => /nl/inspections/pdf/66
[serverParams:protected] => Zend\Stdlib\Parameters Object
(
[storage:ArrayObject:private] => Array
(
[REDIRECT_APP_ENV] => development
[REDIRECT_STATUS] => 200
[APP_ENV] => development
[HTTP_HOST] => keuringapp.localhost
[HTTP_CONNECTION] => close
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_USER_AGENT] => Zend\Http\Client
[PATH] => /usr/bin:/bin:/usr/sbin:/sbin
[SERVER_SIGNATURE] =>
[SERVER_SOFTWARE] => Apache
[SERVER_NAME] => keuringapp.localhost
[SERVER_ADDR] => ::1
[SERVER_PORT] => 80
[REMOTE_ADDR] => ::1
[DOCUMENT_ROOT] => /Applications/MAMP/htdocs/keuringapp/public
[SERVER_ADMIN] => you#example.com
[SCRIPT_FILENAME] => /Applications/MAMP/htdocs/keuringapp/public/index.php
[REMOTE_PORT] => 55447
[REDIRECT_URL] => /nl/inspections/pdf/66
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[REQUEST_URI] => /nl/inspections/pdf/66
[SCRIPT_NAME] => /index.php
[PHP_SELF] => /index.php
[REQUEST_TIME_FLOAT] => 1562241261.33
[REQUEST_TIME] => 1562241261
[argv] => Array
(
)
[argc] => 0
)
)
This question can be closed. It was a problem due to a language setting in the url

Invalid character found in method name. HTTP method names must be tokens, persists even with http request

I am trying to warm up my controller so that the service gets hot during each deployment.
In order to do this i have written a perl script as below:
#!perl
use strict;
use warnings;
use WWW::Mechanize;
use HTTP::Request;
my $ua = WWW::Mechanize->new();
my $r = HTTP::Request->new(
'GET' =>
'http://gaurav_setia.microsoft.com:8080/b2h/homepage?_encoding=UTF8&opf_redir=1&portalDebug=1',
[
'Connection' => 'Keep-Alive',
'Via' => 'HTTP/1.1 ShoppingSchedule',
'Accept' =>
'text/x-html-parts,text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Charset' => 'UTF-8',
'Accept-Encoding' => 'identity',
'Accept-Language' => 'en-US',
'Host' => 'gaurav_setia.microsoft.com',
'User-Agent' =>
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36',
'Cookie' =>
'Original-X-Forwarded-For' => '10.45.103.166',
'X-MS-Internal-Ip-Class' => 'rfc1918',
'X-MS-Internal-Via' =>
'1.1 us-beta-opf-1a-1-67440dc2.us-east-1.ms.com (OPF)',
'X-MS-Urlspace' => 'NoPageType',
'X-MS-Portal-Customer-Id' => 'AMY4OD2PMM9T31',
'X-MS-Portal-Default-Merchant-Id' => 'BTLPDKIKX0DE41',
'X-MS-Portal-Device-Attr' => 'desktop',
'X-MS-Portal-Language' => 'en_US',
'X-MS-Portal-Marketplace-Id' => 'ATVPDKIKX0DER',
'X-MS-Portal-Page-Type' => 'AQGate',
'X-MS-Portal-Request-Attr' => 'internal, http, portal-debug',
'X-MS-Portal-Session-Id' => '1M0-493PO66-0596753',
'X-MS-Portal-Ubid' => '1P2-465OP632-8831161',
'X-MS-Portal-User-Attr' => 'business',
'X-MS-Rid' => 'G308MPK95BWTA69EY2MW',
'X-Forwarded-For' => '10.45.101.126',
'X-Forwarded-Host' => 'development.ms.com',
'X-Forwarded-Server' =>
'development.ms.com, b-hp-shpomnpng-na-2b-02af3555.us-west-2.amazon.com',
'X-Original-Args' => 'portalDebug=1',
'X-Original-Method' => 'GET',
'X-Original-Scheme' => 'http',
'X-Original-Uri' => '/',
],
);
my $res = $ua->request( $r, );
if ( $res->is_success() )
{
print $response->is_success();
}
print $response->status_line;
This script should run after each deployment.
But in the catalina.out logs i am getting the following error:
Dec 13, 2018 9:08:11 AM org.apache.coyote.http11.AbstractHttp11Processor process
INFO: Error parsing HTTP request header
Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
at org.apache.coyote.http11.AbstractNioInputBuffer.parseRequestLine(AbstractNioInputBuffer.java:235)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1055)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
I am unable to find the fix!
Many answers say that this is due to https/http issue, but i am making a http call here itself!
In amongst your pile of headers, you have this:
'User-Agent' =>
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36',
'Cookie' =>
'Original-X-Forwarded-For' => '10.45.103.166',
Notice that there's no value for the Cookie header. That means all of the headers after that will be wrong (the names and values will be muddled up).
Either remove the Cookie line completely or set its value to undef.
'Cookie' => undef,
(Removing it is probably best)

Hashes of Arrays of Hashes of Arrays

I have the following output from hash in perl:
$VAR1 = {
'ins_api' => {
'sid' => 'eoc',
'outputs' => {
'output' => [
{
'body' => {
'TABLE_interface' => {
'ROW_interface' => [
{
'vdc_lvl_in_pkts' => 17081772,
'vdc_lvl_in_avg_bits' => 3128,
'eth_autoneg' => 'on',
'eth_speed' => '1000 Mb/s',
'admin_state' => 'up',
'vdc_lvl_out_mcast' => '65247',
'state' => 'up',
'eth_mtu' => '1500',
'eth_hw_addr' => '78ba.f9ad.b248',
'eth_mdix' => 'off',
'interface' => 'mgmt0',
'eth_ip_addr' => '10.56.32.84',
'eth_bw' => 1000000,
'vdc_lvl_in_avg_pkts' => '3',
'vdc_lvl_out_bytes' => '3463952330',
'vdc_lvl_in_ucast' => '7653891',
'eth_ip_prefix' => '10.',
'eth_rxload' => '1',
'eth_txload' => '1',
'eth_reliability' => '255',
'eth_dly' => 10,
'vdc_lvl_in_mcast' => '8742911',
'eth_ip_mask' => 24,
'eth_bia_addr' => '78ba.f9ad.b248',
'eth_duplex' => 'full',
'vdc_lvl_out_pkts' => '8668507',
'vdc_lvl_out_avg_pkts' => '1',
'vdc_lvl_in_bcast' => '684970',
'vdc_lvl_out_avg_bits' => '1840',
'medium' => 'broadcast',
'vdc_lvl_out_bcast' => '5',
'vdc_lvl_out_ucast' => '8603255',
'eth_ethertype' => '0x0000',
'vdc_lvl_in_bytes' => '1985125644',
'eth_hw_desc' => 'GigabitEthernet'
},
{
'eth_babbles' => '0',
'eth_outbytes' => '7362149107971',
'eth_outucast' => '16348249961',
'eth_clear_counters' => 'never',
'eth_watchdog' => '0',
'eth_inpkts' => 8644872191,
'eth_inbytes' => '3415386845315',
'eth_out_flowctrl' => 'off',
'eth_bad_proto' => '0',
'eth_frame' => '0',
----- output omitted -------
},
What would be the best way to loop via ROW_interface array and print some of the elements? I am just trying to get the elements in the ROW_interface array.
my $ROW_Interfaces = $output->{body}{TABLE_interface}{ROW_interface};
for my $ROW_Interfaces (#$ROW_Interfaces) {
...
}
It seems there can be more than one output, so you'll have to locate the appropriate one similarly.
Similar to #ikegami's answer, but handles the multiple output entries. The if defined... is there as the structure isn't complete, and I wasn't sure if each entry had the same keys or not.
for my $output (#{ $VAR1->{ins_api}{outputs}{output} }){
for my $row_int (#{ $output->{body}{TABLE_interface}{ROW_interface} }){
print "$row_int->{eth_frame}\n" if exists $row_int->{eth_frame};
}
}

Parsing this kind of data

I have written a wrapper for an API. Previously I'd worked on simple string-based GET requests to PHP scripts using Perl.
As part of analysing the response, I have to analyse the following data which appears to be an object. Unfortunately, I'm not sure how to extract usable data from this.
print Dumper on the data returns this:
$VAR1 = bless( {
'_rc' => '200',
'_request' => bless( {
'_uri_canonical' => bless( do{\(my $o = 'http://example.com/?list=1&token=h_DQ-3lru6uy_Zy0w-KXGbPm_b9llY3LAAAAALSF1roAAAAANxAtg49JqlUAAAAA')}, 'URI::http' ),
'_content' => '',
'_uri' => $VAR1->{'_request'}{'_uri_canonical'},
'_method' => 'GET',
'_headers' => bless( {
'accept-charset' => 'iso-8859-1,*,utf-8',
'accept' => 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*',
'cookie' => 'GUID=cHoW3DLOljP4K9LzposM',
'user-agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20041107 Firefox/1.0',
'authorization' => 'Basic YWRtaW46bmljb2xl',
'cookie2' => '$Version="1"',
'::std_case' => {
'cookie' => 'Cookie',
'cookie2' => 'Cookie2'
},
'accept-language' => 'en-US'
}, 'HTTP::Headers' )
}, 'HTTP::Request' ),
'_headers' => bless( {
'client-peer' => 'myip:8085',
'content-type' => 'text/plain',
'cache-control' => 'no-cache',
'connection' => 'keep-alive',
'client-date' => 'Sat, 18 Jul 2015 12:41:00 GMT',
'::std_case' => {
'client-response-num' => 'Client-Response-Num',
'set-cookie2' => 'Set-Cookie2',
'client-date' => 'Client-Date',
'client-peer' => 'Client-Peer',
'set-cookie' => 'Set-Cookie'
},
'client-response-num' => 1,
'content-length' => '8684'
}, 'HTTP::Headers' ),
'_msg' => 'OK',
'_protocol' => 'HTTP/1.1',
'_content' => '{"build":30470,"torrents": [
["043CC5FA0C741CDAD9D2E5CC20DF64A4A400FA34",136,"Epi.S01E03.720p.HDTV.x264-IMMERSE[rarbg]",690765843,39,26951680,671744,24,0,0,0,"",0,1454,0,114,2436,1,663814163,"","","Stopped","512840d7",1437022635,0,"","/mydir/Epi.S01E03.720p.HDTV.x264-IMMERSE[rarbg]",0,"0368737A",false],
["097AA60280AE3E4BA8741192CB015EE06BD9F992",200,"Epi.S01E04.HDTV.x264-KILLERS[ettv]",221928759,1000,221928759,8890308649,40059,0,0,0,"",0,1461,0,4395,65536,-1,0,"","","Queued Seed","512840d8",1437022635,1437023190,"","/mydir/Epi.S01E04.HDTV.x264-KILLERS[ettv]",0,"8F52310A",false]],
"label": [],"torrentc": "350372445"
,"rssfeeds": []
,"rssfilters": []
}
',
'_msg' => 'OK',
'_protocol' => 'HTTP/1.1'
}, 'HTTP::Response' );
I would like to extract each of the following strings from the returned object
097AA60280AE3E4BA8741192CB015EE06BD9F992
200
Epi.S01E04.HDTV.x264-KILLERS[ettv]
Unfortunately, my understanding of objects in Perl is very elementary.
The original code which returns this data looks like this:
my $ua = LWP::UserAgent->new();
my $response = $ua->get( $url, #ns_headers );
print Dumper($response);
How can I work on the strings that of interest?
If you read the documentation for HTTP::Response, you will see that there is a content method, which will return the content of your HTTP message, and a decoded_content method that does the same but also decompresses the data if it happens to be compressed (in your case the data is uncompressed.)
In this case it looks like the content is encoded as JSON data, so you will also need to load the JSON module to decode it into a Perl data structure
For example
use JSON 'from_json';
my $content = from_json $response->decoded_content;
my $torrents = $content->{torrents};
for my $torrent ( #$torrents ) {
say for #$torrent[0,1,2];
say '';
}
output
043CC5FA0C741CDAD9D2E5CC20DF64A4A400FA34
136
Epi.S01E03.720p.HDTV.x264-IMMERSE[rarbg]
097AA60280AE3E4BA8741192CB015EE06BD9F992
200
Epi.S01E04.HDTV.x264-KILLERS[ettv]

Perl Hash Array foreach issue

I have a response which is displayed through Data::Dumper - Dumper($cat_response->result->{'categories'})
$VAR1 = { 'literature' => '1120', 'law' => '1153', 'arts and crafts' => '1132', 'children' => '1141', 'hobbies' => '1133', 'economy' => '1166', 'jobs' => '1140', 'media' => '1144', 'music' => '1147', 'animals' => '1170', 'business' => '1119', 'diet' => '1122', 'travel reviews' => '1154', 'jewelry' => '1157', 'movies' => '1146', 'television' => '1125', 'politics' => '1168', 'internet' => '1139', 'history' => '1129', 'recipes' => '1156', 'press releases' => '1151', 'presents' => '1128', 'marketing' => '1143', 'translations' => '1162', 'fashion' => '1145', 'technology' => '1163', 'real estate' => '1138', 'computer' => '1173', 'automobile' => '1116', 'finances' => '1126', 'weddings' => '1134', 'games' => '1127', 'esoterism' => '1124', 'horoscopes' => '1135', 'shopping' => '1123', 'humor' => '1137', 'miscellaneous' => '1159', 'science' => '1167', 'programming' => '1152', 'languages' => '1161', 'beauty' => '1117', 'sports' => '1160', 'hotels' => '1136', 'plants' => '1149', 'education' => '1118', 'traveling' => '1155', 'health' => '1130', 'telecommunication' => '1164', 'environment' => '1171', 'software' => '1158', 'sweepstakes' => '1131', 'logistics' => '1142', 'home and family' => '1169', 'news' => '1148' };
To access it, I use:
my %categories = $cat_response->result->{'categories'};
foreach my $cat (keys (%categories)) {
<option value="<% $categories{'$cat'} %>"><% $cat %></option>
}
However, the value of Dumper($cat) is: $VAR1 = 'HASH(0x7fe972641560)';
Did I miss something?
You missing use strict; use warnings; for one. (Well, either that, or you forgot to tell us that Perl told you about your problem.)
$cat_response->result->{'categories'} contains a reference to a hash. Makes no sense to assign that to a hash.
my $categories = $cat_response->result->{'categories'};
foreach my $cat (keys (%$categories)) {
<option value="<% $categories->{'$cat'} %>"><% $cat %></option>
}