Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP SDK LexRuntimeService Error: JSON ParserException when calling $client->postContent() #1813

Closed
00j opened this issue Jun 5, 2019 · 1 comment · Fixed by #1819
Closed
Assignees
Labels
bug This issue is a bug.

Comments

@00j
Copy link

00j commented Jun 5, 2019

Hi,

Please can you help?

When calling $client->postContent() the SDK is throwing an exception in aws/aws-sdk-php/src/Api/Parser/PayloadParserTrait.php

It appears to be an issue related to the returning response rather than the request.

Please fill out the sections below to help us address your issue.

Version of AWS SDK for PHP?

3.99.1

Version of PHP (php -v)?

PHP 7.1.27

Composer Show

php composer.phar show aws/aws-sdk-php

name     : aws/aws-sdk-php
descrip. : AWS SDK for PHP - Use Amazon Web Services in your PHP project
keywords : amazon, aws, cloud, dynamodb, ec2, glacier, s3, sdk
versions : * 3.99.1
type     : library
license  : Apache License 2.0 (Apache-2.0) (OSI approved) https://spdx.org/licenses/Apache-2.0.html#licenseText
source   : [git] https://github.com/aws/aws-sdk-php.git 455e93cc4feb99847f88f4229659da2c79aa6371
dist     : [zip] https://api.github.com/repos/aws/aws-sdk-php/zipball/455e93cc4feb99847f88f4229659da2c79aa6371 455e93cc4feb99847f88f4229659da2c79aa6371
path     : xxxx/library/vendor/aws/aws-sdk-php
names    : aws/aws-sdk-php

autoload
psr-4
Aws\ => src/
files

requires
ext-json *
ext-pcre *
ext-simplexml *
guzzlehttp/guzzle ^5.3.3|^6.2.1
guzzlehttp/promises ~1.0
guzzlehttp/psr7 ^1.4.1
mtdowling/jmespath.php ~2.2
php >=5.5

requires (dev)
andrewsville/php-token-reflection ^1.4
aws/aws-php-sns-message-validator ~1.0
behat/behat ~3.0
doctrine/cache ~1.4
ext-dom *
ext-openssl *
ext-pcntl *
ext-sockets *
nette/neon ^2.3
phpunit/phpunit ^4.8.35|^5.4.3
psr/cache ^1.0
psr/simple-cache ^1.0

suggests
aws/aws-php-sns-message-validator To validate incoming SNS notifications
doctrine/cache To use the DoctrineCacheAdapter
ext-curl To send requests using cURL
ext-openssl Allows working with CloudFront private distributions and verifying received SNS messages
ext-sockets To use client-side monitoring

What issue did you see?

PHP Fatal error:  Uncaught Aws\Api\Parser\Exception\ParserException: Error parsing JSON: Syntax error in /mnt/efs/src/library/vendor/aws/aws-sdk-php/src/Api/Parser/PayloadParserTrait.php:21
Stack trace:
#0 /mnt/efs/src/library/vendor/aws/aws-sdk-php/src/Api/Parser/AbstractRestParser.php(132): Aws\Api\Parser\AbstractRestParser->parseJson('', Object(GuzzleHttp\Psr7\Response))
#1 /mnt/efs/src/library/vendor/aws/aws-sdk-php/src/Api/Parser/AbstractRestParser.php(46): Aws\Api\Parser\AbstractRestParser->extractHeader('sessionAttribut...', Object(Aws\Api\Shape), Object(GuzzleHttp\Psr7\Response), Array)
#2 /mnt/efs/src/library/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php(125): Aws\Api\Parser\AbstractRestParser->__invoke(Object(Aws\Command), Object(GuzzleHttp\Psr7\Response))
#3 /mnt/efs/src/library/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php(92): Aws\WrappedHttpHandler->parseResponse(Object(Aws\Command), Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response), Array)
#4 / in /mnt/efs/src/library/vendor/aws/aws-sdk-php/src/Api/Parser/PayloadParserTrait.php on line 21

Steps to reproduce

The following snippet will generate this error

$awsAccessKeyId = 'XXXXXXXXX';
$awsSecretKey   = 'YYYYYYYYY';
$credentials    = new \Aws\Credentials\Credentials($awsAccessKeyId, $awsSecretKey);

#Client
$client         = new \Aws\LexRuntimeService\LexRuntimeServiceClient([
    'version'     => '2016-11-28',
    'credentials' => $credentials,
    'region'      => 'eu-west-1',
    'debug'       => true
]);


$file_contents = file_get_contents('bookholiday.raw');

$result = $client->postContent([
    'accept' => 'text/plain; charset=utf-8',
    'botAlias' => '$LATEST',
    'botName' => 'BookHoliday',
    'contentType' => 'audio/lpcm; sample-rate=8000; sample-size-bits=16; channel-count=1; is-big-endian=false',
    'inputStream' => $file_contents,
    'userId' => 'caller123'
]);

print_r($result);

Sample Audio:

bookholiday.zip

Additional context

The following is an extract from the output of debug, I can provide more if required :

-> Entering step attempt, name 'ApiCallAttemptMonitoringMiddleware'
-------------------------------------------------------------------

  no changes

*   Trying 52.49.196.186...
* TCP_NODELAY set
* Connected to runtime.lex.eu-west-1.amazonaws.com (52.49.196.186) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=*.runtime.lex.eu-west-1.amazonaws.com
*  start date: Sep 12 00:00:00 2018 GMT
*  expire date: Oct 12 12:00:00 2019 GMT
*  subjectAltName: host "runtime.lex.eu-west-1.amazonaws.com" matched cert's "runtime.lex.eu-west-1.amazonaws.com"
*  issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
*  SSL certificate verify ok.
> POST /bot/BookHoliday/alias/%24LATEST/user/caller-30000-6431/content HTTP/1.1
Host: runtime.lex.eu-west-1.amazonaws.com
Accept: text/plain; charset=utf-8
Content-Type: audio/lpcm; sample-rate=8000; sample-size-bits=16; channel-count=1; is-big-endian=false
transfer-encoding: chunked
aws-sdk-invocation-id: 117a34ba1c2cf82ffe287068d0e16a98
aws-sdk-retry: 0/0
X-Amz-Date: 20190605T022401Z
X-Amz-Content-Sha256: UNSIGNED-PAYLOAD
Authorization: AWS4-HMAC-SHA256 Credential=[KEY]/20190605/eu-west-1/lex/aws4_request, SignedHeaders=host;transfer-encoding;x-amz-content-sha256;x-amz-date, Signature=[SIGNATURE]
User-Agent: aws-sdk-php/3.99.1 GuzzleHttp/6.3.3 curl/7.52.1 PHP/7.1.27-1+0~20190307202204.14+stretch~1.gbp7163d5

< HTTP/1.1 200 OK
< Content-Type: text/plain;charset=utf-8
< Date: Wed, 05 Jun 2019 02:24:02 GMT
< x-amz-lex-dialog-state: ElicitSlot
< x-amz-lex-input-transcript: please can i book a holiday
< x-amz-lex-intent-name: BookHotel
< x-amz-lex-message: What city will you be staying in?
< x-amz-lex-message-format: PlainText
< x-amz-lex-slot-to-elicit: Location
< x-amz-lex-slots: eyJEZWNyaWJsZUR1cmF0aW9uVmFyaWFudHMiOm51bGwsIlJvb21UeXBlIjpudWxsLCJDaGVja0luRGF0ZSI6bnVsbCwiTmlnaHRzIjpudWxsLCJEZWNyaWJsZUhvbGlkYXlWYXJpYW50cyI6ImhvbGlkYXkiLCJzbG90U2V2ZW4iOm51bGwsIkxvY2F0aW9uIjpudWxsfQ==
< x-amzn-RequestId: fb3e8f13-8738-11e9-bb5d-d32934ef7580
< Content-Length: 0
< Connection: keep-alive
<
* Curl_http_done: called premature == 0
* Connection #0 to host runtime.lex.eu-west-1.amazonaws.com left intact

<- Leaving step attempt, name 'ApiCallAttemptMonitoringMiddleware'
------------------------------------------------------------------

  error was set to array(6) {
    ["instance"]=>
    string(32) "000000000ac8202c000000005c56b4e3"
    ["class"]=>
    string(40) "Aws\Api\Parser\Exception\ParserException"
    ["message"]=>
    string(32) "Error parsing JSON: Syntax error"
    ["file"]=>
    string(90) "/mnt/efs/src/library/vendor/aws/aws-sdk-php/src/Api/Parser/PayloadParserTrait.php"
    ["line"]=>
    int(21)
    ["trace"]=>
    string(2820) "#0 /mnt/efs/src/library/vendor/aws/aws-sdk-php/src/Api/Parser/AbstractRestParser.php(132): Aws\Api\Parser\AbstractRestParser->parseJson('', Object(GuzzleHttp\Psr7\Response))
  #1 /mnt/efs/src/library/vendor/aws/aws-sdk-php/src/Api/Parser/AbstractRestParser.php(46): Aws\Api\Parser\AbstractRestParser->extractHeader('sessionAttribut...', Object(Aws\Api\Shape), Object(GuzzleHttp\Psr7\Response), Array)
  #2 /mnt/efs/src/library/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php(125): Aws\Api\Parser\AbstractRestParser->__invoke(Object(Aws\Command), Object(GuzzleHttp\Psr7\Response))
  #3 /mnt/efs/src/library/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php(92): Aws\WrappedHttpHandler->parseResponse(Object(Aws\Command), Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response), Array)
  #4 /mnt/efs/src/library/vendor/guzzlehttp/promises/src/Promise.php(203): Aws\WrappedHttpHandler->Aws\{closure}(Object(GuzzleHttp\Psr7\Response))
  #5 /mnt/efs/src/library/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
  #6 /mnt/efs/src/library/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
  #7 /mnt/efs/src/library/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(98): GuzzleHttp\Promise\TaskQueue->run()
  #8 /mnt/efs/src/library/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(125): GuzzleHttp\Handler\CurlMultiHandler->tick()
  #9 /mnt/efs/src/library/vendor/guzzlehttp/promises/src/Promise.php(246): GuzzleHttp\Handler\CurlMultiHandler->execute(true)
  #10 /mnt/efs/src/library/vendor/guzzlehttp/promises/src/Promise.php(223): GuzzleHttp\Promise\Promise->invokeWaitFn()
  #11 /mnt/efs/src/library/vendor/guzzlehttp/promises/src/Promise.php(267): GuzzleHttp\Promise\Promise->waitIfPending()
  #12 /mnt/efs/src/library/vendor/guzzlehttp/promises/src/Promise.php(225): GuzzleHttp\Promise\Promise->invokeWaitList()
  #13 /mnt/efs/src/library/vendor/guzzlehttp/promises/src/Promise.php(267): GuzzleHttp\Promise\Promise->waitIfPending()
  #14 /mnt/efs/src/library/vendor/guzzlehttp/promises/src/Promise.php(225): GuzzleHttp\Promise\Promise->invokeWaitList()
  #15 /mnt/efs/src/library/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
  #16 /mnt/efs/src/library/vendor/aws/aws-sdk-php/src/AwsClientTrait.php(58): GuzzleHttp\Promise\Promise->wait()
  #17 /mnt/efs/src/library/vendor/aws/aws-sdk-php/src/AwsClientTrait.php(86): Aws\AwsClient->execute(Object(Aws\Command))
  #18 /mnt/efs/src/testing/aws/asr/lex_file.php(162): Aws\AwsClient->__call('postContent', Array)
  #19 {main}"
  }

  Inclusive step time: 1.0794389247894

@diehlaws diehlaws added investigating This issue is being investigated and/or work is in progress to resolve the issue. bug This issue is a bug. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Jun 7, 2019
@srchase
Copy link
Contributor

srchase commented Jun 13, 2019

This will be resolved in the next release of the SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants