Postmark/Guzzle InvalidArgumentException:无效的资源类型:布尔值
Postmark/Guzzle InvalidArgumentException: Invalid resource type: boolean
我不断收到一些通过 Postmark 发送的电子邮件的 InvalidArgumentException: Invalid resource type: boolean
。有些在工作,有些则没有。我看不出正常工作的电子邮件和有错误的电子邮件之间有什么不同。它们是 运行 具有相同参数的相同代码。
这是我传递给 Postmark 的内容:
$client = new PostmarkClient($config->postmark->token);
$sendResult = $client->sendEmail(
$config->postmark->sender,
$recipient,
$subject,
$html_body,
$text_body,
null, true, null, null, null, null, $attachments
);
调用堆栈如下:
vendor/guzzlehttp/streams/src/Stream.php in factory at line 85
throw new \InvalidArgumentException('Invalid resource type: ' . $type);
vendor/guzzlehttp/guzzle/src/Message/MessageFactory.php in applyOptions at line 345
$request->setBody(Stream::factory(json_encode($value)));
vendor/guzzlehttp/guzzle/src/Message/MessageFactory.php in createRequest at line 98
$this->applyOptions($request, $options);
vendor/guzzlehttp/guzzle/src/Client.php in createRequest at line 120
return $this->messageFactory->createRequest($method, $url, $options);
vendor/wildbit/postmark-php/src/Postmark/PostmarkClientBase.php in processRestRequest at line 101
$request = $client->createRequest($method, $url, $options);
vendor/wildbit/postmark-php/src/Postmark/PostmarkClient.php in sendEmail at line 61
return new DynamicResponseModel($this->processRestRequest('POST', '/email', $body));
library/send_mail.php in send_mail at line 86
我在谷歌上搜索了一段时间,但没有找到任何有意义的东西。
我看过这里:
https://laracasts.com/discuss/channels/general-discussion/mandrill-trouble-invalid-resource-type-boolean
和这里:
https://laracasts.com/forum/?p=2325-problems-using-mandrill/0 但是这两个都与 Laravel+Mandrill 有问题,但我使用的是 Postmark 而没有框架。但是,我们确实有 Guzzle 的共同点。这两个帖子都表示他们通过更新或重新安装他们的 Guzzle 来处理它。
我似乎是 运行 Guzzle 的 "working" 版本。 GitHub Issue #628 for Guzzle 似乎正是我所看到的,但那个问题说它已在 4.0.2 中修复,我在 Guzzle 5.3 上:
来自服务器上我的composer.lock
:
{
"name": "guzzlehttp/guzzle",
"version": "5.3.0"
},
...
{
"name": "guzzlehttp/streams",
"version": "3.0.0"
},
...
{
"name": "wildbit/postmark-php",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/wildbit/postmark-php",
"reference": "2eabc627c3f2a693b986e51d2f892cc2e2d065b3"
},
"require": {
"guzzlehttp/guzzle": "~5.1",
"php": ">=5.4.0"
},
}
有什么想法吗?
如果您的错误不是很明显,那么 call stak 通常会阐明问题所在。这也不例外,我早该注意到的。
调用堆栈中的倒数第二个项目是出错的地方。
$request->setBody(Stream::factory(json_encode($value)));
这里,json_encode($value)
返回一个布尔值。使用 json_last_error()
我能够确定问题出在混合字符编码 (JSON_ERROR_UTF8
) 上。
在用户输入的某处有用户提供的数据,该数据混合了 UTF-8 和 ISO-8895-1。由于这是不一致的,一些电子邮件可以正常工作,而另一些则失败。
我最终强制我的 $html_body
和 $text_body
成为 UTF-8,然后事情开始起作用了。
我不断收到一些通过 Postmark 发送的电子邮件的 InvalidArgumentException: Invalid resource type: boolean
。有些在工作,有些则没有。我看不出正常工作的电子邮件和有错误的电子邮件之间有什么不同。它们是 运行 具有相同参数的相同代码。
这是我传递给 Postmark 的内容:
$client = new PostmarkClient($config->postmark->token);
$sendResult = $client->sendEmail(
$config->postmark->sender,
$recipient,
$subject,
$html_body,
$text_body,
null, true, null, null, null, null, $attachments
);
调用堆栈如下:
vendor/guzzlehttp/streams/src/Stream.php in factory at line 85
throw new \InvalidArgumentException('Invalid resource type: ' . $type);
vendor/guzzlehttp/guzzle/src/Message/MessageFactory.php in applyOptions at line 345
$request->setBody(Stream::factory(json_encode($value)));
vendor/guzzlehttp/guzzle/src/Message/MessageFactory.php in createRequest at line 98
$this->applyOptions($request, $options);
vendor/guzzlehttp/guzzle/src/Client.php in createRequest at line 120
return $this->messageFactory->createRequest($method, $url, $options);
vendor/wildbit/postmark-php/src/Postmark/PostmarkClientBase.php in processRestRequest at line 101
$request = $client->createRequest($method, $url, $options);
vendor/wildbit/postmark-php/src/Postmark/PostmarkClient.php in sendEmail at line 61
return new DynamicResponseModel($this->processRestRequest('POST', '/email', $body));
library/send_mail.php in send_mail at line 86
我在谷歌上搜索了一段时间,但没有找到任何有意义的东西。
我看过这里: https://laracasts.com/discuss/channels/general-discussion/mandrill-trouble-invalid-resource-type-boolean 和这里: https://laracasts.com/forum/?p=2325-problems-using-mandrill/0 但是这两个都与 Laravel+Mandrill 有问题,但我使用的是 Postmark 而没有框架。但是,我们确实有 Guzzle 的共同点。这两个帖子都表示他们通过更新或重新安装他们的 Guzzle 来处理它。
我似乎是 运行 Guzzle 的 "working" 版本。 GitHub Issue #628 for Guzzle 似乎正是我所看到的,但那个问题说它已在 4.0.2 中修复,我在 Guzzle 5.3 上:
来自服务器上我的composer.lock
:
{
"name": "guzzlehttp/guzzle",
"version": "5.3.0"
},
...
{
"name": "guzzlehttp/streams",
"version": "3.0.0"
},
...
{
"name": "wildbit/postmark-php",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/wildbit/postmark-php",
"reference": "2eabc627c3f2a693b986e51d2f892cc2e2d065b3"
},
"require": {
"guzzlehttp/guzzle": "~5.1",
"php": ">=5.4.0"
},
}
有什么想法吗?
如果您的错误不是很明显,那么 call stak 通常会阐明问题所在。这也不例外,我早该注意到的。
调用堆栈中的倒数第二个项目是出错的地方。
$request->setBody(Stream::factory(json_encode($value)));
这里,json_encode($value)
返回一个布尔值。使用 json_last_error()
我能够确定问题出在混合字符编码 (JSON_ERROR_UTF8
) 上。
在用户输入的某处有用户提供的数据,该数据混合了 UTF-8 和 ISO-8895-1。由于这是不一致的,一些电子邮件可以正常工作,而另一些则失败。
我最终强制我的 $html_body
和 $text_body
成为 UTF-8,然后事情开始起作用了。