Mandrill ValidationError

后端 未结 7 2567
花落未央
花落未央 2021-02-20 06:51

Very excited to be asking my first question on StackOverflow. I\'ve been relying on it to teach myself quite a lot over the years!

My question is this. I am getting the

7条回答
  •  深忆病人
    2021-02-20 07:02

    The PHP Mandrill API error: "Mandrill_ValidationError - You must specify a key value"

    This error can also indicate that json_encode() is failing to encode and returning an empty string. When the empty string is submitted to Mandrill via curl, it fails to let you know that it got totally empty POST content, and instead issues the helpful message "You must specify a key value".

    Obviously this problem could be mitigated by better detection at several levels:

    • Mandrill at API level could return an error like "Empty POST"
    • The Mandrill.php API class could return an error like "json_encode fail, possible non-base64 image or content problem"
    • The Mandrill.php API class could check for non-base64 content in images and give an error like "unencoded image"
    • It would be kind of nice if json_encode() threw some sort of error (not sure re this one)

    None of this is being done at this point, hence this was unnecessarily hard to debug.

    The simple fix in my case was to effectively change code to run base64_encode() before including image content, that is:

              'content' => base64_encode(file_get_content("image.jpg"),
    

    A better fix is, as above, to upgrade the Mandrill.php API file to detect a failure to encode and throw an error.

提交回复
热议问题