0

I need to convert this php function, which use CURL to login to an web server and then request a png resource.

function GraphImageById ($graphid, $period = 3600, $width, $height) { global $z_server, $z_user, $z_pass, $z_tmp_cookies, $z_url_index, $z_url_graph, $z_url_api, $z_img_path,   $z_login_data;
    // file names
    $filename_cookie = $z_tmp_cookies ."zabbix_cookie_" .$graphid .".txt";
    $image_name = $z_img_path ."zabbix_graph_" .$graphid .".png";

    //setup curl
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $z_url_index);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $z_login_data);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $filename_cookie);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $filename_cookie);
    // login - 1st curl exec.
    curl_exec($ch);
    // get graph
    curl_setopt($ch, CURLOPT_URL, $z_url_graph ."?graphid=" .$graphid ."&width=" .$width ."&height=" .$height ."&period=" .$period);
    // set response header
    header("Content-type: image/png");
    $output = curl_exec($ch); // - 2nd curl exec.
    curl_close($ch);
    unlink($filename_cookie);
    return $output;

}

Which python lib I can use? Any suggestions? Thanks.

2
  • 1
    SO is not a code writing service. What do you have so far? What problems do you have? Commented Mar 13, 2015 at 16:01
  • I need to post my auth data to the server, save cookie response and make a new request to another "php file" to get a png resource. Commented Mar 13, 2015 at 16:05

1 Answer 1

1

Probably pycurl (cURL lib binding for python) is what you want (https://pypi.python.org/pypi/pycurl), but i'm pretty sure you also can approach this with httplib/httplib2.

Sign up to request clarification or add additional context in comments.

2 Comments

At this time I've solved with python "requests" module.
Good, request is an awesome module by the way!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.