【发布时间】:2014-07-16 15:02:43
【问题描述】:
我正在我的 Windows 机器(Win7 64 位)PHP v 5.5.12 上安装适用于 PHP 的 aws sdk。 我尝试使用 here 提到的所有 3 种方法,即 Composer、zip 和 PHAR。所有 3 种方法都给了我与以下相同的错误。
Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : Space required after the Public Identifier in C:\wamp\www\aws-sdk-php-master\src\Aws\Common\Exception\Parser\DefaultXmlExceptionParser.php on line 41
这是给出错误的函数
public function parse(RequestInterface $request, Response $response)
{
$data = array(
'code' => null,
'message' => null,
'type' => $response->isClientError() ? 'client' : 'server',
'request_id' => null,
'parsed' => null
);
if ($body = $response->getBody(true)) {
$this->parseBody(new \SimpleXMLElement($body), $data); //THIS LINE GIVES ERROR
} else {
$this->parseHeaders($request, $response, $data);
}
return $data;
}
这是我尝试使用它的方法。
error_reporting(E_ALL);
define('AWS_KEY', 'MyAWSKEY');
define('AWS_SECRET_KEY', 'MYSECRETKEY');
define('HOST', 'http://localhost'); //tried changing host to diff values,but don't
//think thats the issue
// require the AWS SDK for PHP library
require 'aws-autoloader.php';
//require '../../aws.phar';
use Aws\S3\S3Client;
// Establish connection with an S3 client.
$client = S3Client::factory(array(
'base_url' => HOST,
'key' => AWS_KEY,
'secret' => AWS_SECRET_KEY
));
$o_iter = $client->getIterator('ListObjects', array(
'Bucket' => 'mybucketname'
));
foreach ($o_iter as $o) {
echo "{$o['Key']}\t{$o['Size']}\t{$o['LastModified']}\n";
}
这是堆栈跟踪
[17-Jul-2014 04:19:01 Europe/Paris] PHP Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\wamp\www\aws-sdk-php-master\src\Aws\Common\Exception\Parser\DefaultXmlExceptionParser.php:41
Stack trace:
#0 C:\wamp\www\aws-sdk-php- master\src\Aws\Common\Exception\Parser\DefaultXmlExceptionParser.php(41): SimpleXMLElement- >__construct('<!DOCTYPE HTML ...')
#1 C:\wamp\www\aws-sdk-php-master\src\Aws\S3\Exception\Parser\S3ExceptionParser.php(33): Aws\Common\Exception\Parser\DefaultXmlExceptionParser->parse(Object(Guzzle\Http\Message\Request), Object(Guzzle\Http\Message\Response))
#2 C:\wamp\www\aws-sdk-php-master\src\Aws\Common\Client\ExpiredCredentialsChecker.php(61): Aws\S3\Exception\Parser\S3ExceptionParser->parse(Object(Guzzle\Http\Message\Request), Object(Guzzle\Http\Message\Response))
#3 C:\wamp\www\aws-sdk-php-master\vendor\guzzle\guzzle\src\Guzzle\Plugin\Backoff\AbstractBackoffStrategy.php(39): Aws\Common\Client\ExpiredCredentialsChecker->getDelay(0, Object(Guzzle\Http\Message\Request), Object(Guzzle\Http\Message\Resp in C:\wamp\www\aws-sdk-php-master\src\Aws\Common\Exception\Parser\DefaultXmlExceptionParser.php on line 41
尝试谷歌搜索并了解到可能是由于 php.ini 中的 magic_quotes 开启,但事实并非如此,实际上我的 ini 文件中没有 magic_quotes 本身。 检查堆栈跟踪,它显示相同的错误。我无法确定它是 系统问题还是某些配置问题,因为我得到了所有方法。 这是某些配置的问题吗?或者我错过了什么?
【问题讨论】:
-
仅供参考:魔术引号已在 PHP 5.4 中删除(耶!)。在解决此问题时您应该做的是实际转储
$body,以便您可以查看尝试解析为 XML 的内容(而不是 XML)。这应该提供更多的洞察力。如果您在转储后仍不确定,请将$body的第一行添加到您的问题中。 (您可能正在解析带有错误消息而不是 XML 的 HTML 页面,比较 stackoverflow.com/q/14465945/367456 这还表明,如果您增加错误日志记录,您可以找到更多不转储$body,因为 PHP 在错误消息中执行此操作)。 -
您使用的是什么服务和操作?你能分享你实际执行操作的代码示例吗?
-
@JeremyLindblom 嘿,我已将代码添加到问题中。我正在尝试使用工厂加载方法使用 S3 客户端。我的自动加载器是默认的,因为我在这里使用了 composer。我认为我不需要改变它。
标签: php xml amazon-web-services xml-parsing