【问题标题】:Mandrill Curl Request Returning Invalid Key ErrorMandrill Curl 请求返回无效密钥错误
【发布时间】:2014-08-05 04:41:33
【问题描述】:

我正在尝试通过 Mandrill API 发送电子邮件,但它使用我提供的密钥引发错误。下面是我在 curl 请求中包含的 text.json 文件。

{
'key' : 'MyActualKey',
'message': {
    'html': '<p>Example HTML content</p>',
    'text': 'Example text content',
    'subject': 'example subject',
    'from_email': 'from@example.com',
    'from_name': 'Test',
    'to': [
        {
            'email': 'to@example.com',
            'name': 'Eric Clapton',
            'type': 'to'
        }
    ],
    'headers': {
        'Reply-To': 'reply@example.com'
    },
    'merge': True,
    'tags': [
        'Mandrill Test'
    ]
 },
'ip_pool': 'Main Pool'
}

然后我执行这个 curl 命令:

curl -X POST -H "Content-Type: application/json" --data @test.json https://mandrillapp.com/api/1.0/messages/send.json -v

导致此输出,最后一行显示错误:

* Adding handle: conn: 0x7fd922803a00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fd922803a00) send_pipe: 1, recv_pipe: 0
* About to connect() to mandrillapp.com port 443 (#0)
*   Trying 54.221.22.61...
* Connected to mandrillapp.com (54.221.22.61) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
* Server certificate: mandrillapp.com
* Server certificate: Thawte SSL CA
* Server certificate: thawte Primary Root CA
* Server certificate: Thawte Premium Server CA
> POST /api/1.0/messages/send.json HTTP/1.1
> User-Agent: curl/7.30.0
> Host: mandrillapp.com
> Accept: */*
> Content-Type: application/json
> Content-Length: 501
>
* upload completely sent off: 501 out of 501 bytes
< HTTP/1.1 500 Internal Server Error
* Server nginx/1.6.0 is not blacklisted
< Server: nginx/1.6.0
< Date: Sat, 14 Jun 2014 23:46:44 GMT
< Content-Type: application/json; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Powered-By: PHP/5.3.10-1ubuntu3.11
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: POST, GET, OPTIONS
< Access-Control-Allow-Headers: Content-Type
< Access-Control-Allow-Credentials: false
<
* Connection #0 to host mandrillapp.com left intact
{"status":"error","code":-1,"name":"ValidationError","message":"You must specify a key value"}

注意最后一行是如何说“指定一个键值”的——同样,这正是 Mandrill 控制面板中的键。我什至又生成了几个,但都失败了。

【问题讨论】:

    标签: json api post curl mandrill


    【解决方案1】:

    尝试将其更改为有效的 json,看看是否有帮助:

    1. 将所有单引号改为双引号
    2. 将“merge”的值从“True”更改为小写“true”。

    【讨论】:

    • 遇到了类似的问题。它不喜欢单引号的类型(我猜是撇号?)所以将`更改为'
    猜你喜欢
    • 2018-07-01
    • 2019-03-09
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 2011-10-09
    • 1970-01-01
    • 2017-07-03
    • 1970-01-01
    相关资源
    最近更新 更多