Fatal error: Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception - php

So I am using elasticsearch.
I have this code:
<?php
error_reporting(E_ALL);ini_set('display_errors', 1);
require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
$hosts = [
'http://localhost:80', // SSL to localhost
];
$clientBuilder = ClientBuilder::create(); // Instantiate a new ClientBuilder
$clientBuilder->setHosts($hosts); // Set the hosts
$client = $clientBuilder->build();
$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id',
'body' => ['testField' => 'abc']
];
$response = $client->index($params);
print_r($response);
I get this error:
Fatal error: Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception: 405 Method Not Allowed Method Not Allowed The requested method PUT is not allowed for the URL /my_index/my_type/my_id. in C:\Bitnami\wampstack-7.0.0RC7-\apache2\htdocs\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\Connection.php:615 Stack trace: #0 C:\Bitnami\wampstack-7.0.0RC7-\apache2\htdocs\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\Connection.php(279): Elasticsearch\Connections\Connection->process4xxError(Array, Array, Array) #1 C:\Bitnami\wampstack-7.0.0RC7-\apache2\htdocs\vendor\react\promise\src\FulfilledPromise.php(25): Elasticsearch\Connections\Connection->Elasticsearch\Connections{closure}(Array) #2 C:\Bitnami\wampstack-7.0.0RC7-\apache2\htdocs\vendor\guzzlehttp\ringphp\src\Future\CompletedFutureValue.php(55): React\Promise\FulfilledPromise->then(Object(Closure), NULL, NU in C:\Bitnami\wampstack-7.0.0RC7-\apache2\htdocs\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\Connection.php on line 615

I GOT IT!
I just had to change
$hosts = [
'http://localhost:80', // SSL to localhost
];
To
$hosts = [
'http://localhost:80' // SSL to localhost
];
(remove the comma)

Related

I am not able to get signed url in cloudfront, getting fatal error, code I am trying is below

<?php
require '../aws-autoloader.php';
use Aws\CloudFront\CloudFrontClient;
use Aws\Exception\AwsException;
// Create a CloudFront Client
$client = new Aws\CloudFront\CloudFrontClient([
'profile' => 'default',
'version' => 'latest',
'region' => 'us-east-1',
]);
// Set up parameter values for the resource
$resourceKey = 'https://example.cloudfront.net/b20cbfe5-a8df-47a5-94c4-aeadea20759f/dash/videoplayback.mpd';
$expires = time() + 300;
// Create a signed URL for the resource using the canned policy
$signedUrlCannedPolicy = $client->getSignedUrl([
'url' => $resourceKey,
'expires' => $expires,
'private_key' => 'pk.pem',
'key_pair_id' => 'keyid'
]);
getting error as
Fatal error: Uncaught InvalidArgumentException: error:0906D06C:PEM routines:PEM_read_bio:no start line in C:\xampp\htdocs\aws\Aws\CloudFront\Signer.php:40 Stack trace: #0 C:\xampp\htdocs\aws\Aws\CloudFront\UrlSigner.php(24): Aws\CloudFront\Signer->__construct('APKAJYH2L6BGHLW...', 'pk-APKAJYH2L6BG...') #1 C:\xampp\htdocs\aws\Aws\CloudFront\CloudFrontClient.php(138): Aws\CloudFront\UrlSigner->__construct('APKAJYH2L6BGHLW...', 'pk-APKAJYH2L6BG...') #2 C:\xampp\htdocs\aws\app\stream.php(26): Aws\CloudFront\CloudFrontClient->getSignedUrl(Array) #3 {main} thrown in C:\xampp\htdocs\aws\Aws\CloudFront\Signer.php on line 40
I have resolved this issue. The issue was you need to give absolute path in below like this
'private_key' => $_SERVER['DOCUMENT_ROOT'] . '/' . 'pk.pem',
Let me know if it's working or not?

How do I request fund in coinbase api?

Hi I am trying to use coinbase api in php.api implementation working fine, I can check balance, creat new address all this are working fine.But facing problem on request bitcoin. I am following coinbase official api librery , accroding documention on mentioned link request fund usage code is
use Coinbase\Wallet\Enum\CurrencyCode;
use Coinbase\Wallet\Resource\Transaction;
use Coinbase\Wallet\Value\Money;
$transaction = Transaction::request([
'amount' => new Money(8, CurrencyCode::USD),
'description' => 'Burrito'
]);
$client->createAccountTransaction($transaction);
And I used exactly what they said, but I am getting error, bellow is my code
<?php
require_once('vendor/autoload.php');
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
use Coinbase\Wallet\Enum\CurrencyCode;
use Coinbase\Wallet\Resource\Transaction;
use Coinbase\Wallet\Value\Money;
$apiKey='xxxxxxx';
$apiSecret='xxxxxxx';
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$transaction = Transaction::request([
'amount' => new Money(8, CurrencyCode::USD),
'description' => 'Burrito'
]);
$client->createAccountTransaction($transaction);
echo json_encode($client->decodeLastResponse());
?>
And error is
Fatal error: Uncaught TypeError: Argument 1 passed to
Coinbase\Wallet\Client::createAccountTransaction() must be an instance
of Coinbase\Wallet\Resource\Account, instance of
Coinbase\Wallet\Resource\Transaction given, called in
/file_path/file.php on line 19 and defined in
/library_path /vendor/coinbase/coinbase/src/Client.php:359 Stack
trace: #0 /file_path/file.php(19):
Coinbase\Wallet\Client->createAccountTransaction(Object(Coinbase\Wallet\Resource\Transaction))
1 {main} thrown in /library_path /vendor/coinbase/coinbase/src/Client.php on line 359
update:
I tried by adding specific account parameter
$account=$client->getPrimaryAccount();
$transaction = Transaction::request([
'amount' => new Money(8, CurrencyCode::USD),
'description' => 'Burrito'
]);
$client->createAccountTransaction($account,$transaction);
And then I got error exception To peremeter missing so I added to parameter
Transaction::request([
'to'=>'test#mail.com',
'amount' => new Money(8, CurrencyCode::USD),
'description' => 'Burrito'
]);
And now error is
Fatal error: Uncaught TypeError: Argument 1 passed to
Coinbase\Wallet\Resource\Transaction::setTo() must be an instance of
Coinbase\Wallet\Resource\Resource, string given, called in
/home/exhakduz/api/vendor/coinbase/coinbase/src/Resource/Resource.php
on line 70 and defined in /library_path
/vendor/coinbase/coinbase/src/Resource/Transaction.php:199 Stack
trace: #0 /library_path
/vendor/coinbase/coinbase/src/Resource/Resource.php(70):
Coinbase\Wallet\Resource\Transaction->setTo('test#mail.com') #1
/library_path /vendor/coinbase/coinbase/src/Resource/Resource.php(25):
Coinbase\Wallet\Resource\Resource->updateAttributes(Array) #2
/library_path
/vendor/coinbase/coinbase/src/Resource/Transaction.php(119):
Coinbase\Wallet\Resource\Resource->__construct('transaction', Array)
3 /library_path /vendor/coinbase/coinbase/src/Resource/Transaction.php(114):
Coinbase\Wallet\Resource\Transaction->__construct('request', Array) #4
/library_path /receive.php(20):
Coinbase\Wallet\Resource\Transaction::request(Ar in /library_path
/vendor/coinbase/coinbase/src/Resource/Transaction.php on line 199
Your call should also reference $account:
$account = $client->getPrimaryAccount();
$transaction = Transaction::request([
'amount' => new Money(8, CurrencyCode::USD),
'description' => 'Burrito'
]);
$client->createAccountTransaction($account, $transaction);
Try
$client->createAccountTransaction($account, $transaction);
Transaction::request([
'toEmail'=>'test#mail.com',
'amount' => new Money(8, CurrencyCode::USD),
'description' => 'Burrito'
]);
$client->createAccountTransaction($account, $transaction);

Paginating List Cognito Identities in AWS PHP SDK v3

How do I fetch all records when the result is paginated, using the AWS PHP SDK v3? I have the following code:
require_once 'vendor/autoload.php';
$cognitoIdentityClient = new Aws\CognitoIdentity\CognitoIdentityClient([
'region' => 'eu-west-1',
'version' => '2014-06-30',
'credentials' => [
'key' => '**************',
'secret' => '***************',
],
]);
$identities = $cognitoIdentityClient->getPaginator('ListIdentities', [
'IdentityPoolId' => 'eu-west-1:****************************',
]);
which looks like it should work, but produces the error:
Fatal error: Uncaught UnexpectedValueException: There is no ListIdentities paginator defined for the cognito-identity service. in /path/to/vendor/aws/aws-sdk-php/src/Api/Service.php:363
Stack trace:
#0 /path/to/vendor/aws/aws-sdk-php/src/AwsClientTrait.php(23): Aws\Api\Service->getPaginatorConfig('ListIdentities')
#1 /path/to/report.php(24): Aws\AwsClient->getIterator('ListIdentities', Array)
#2 {main}
thrown in /path/to/vendor/aws/aws-sdk-php/src/Api/Service.php on line 363
The getPaginator method exists, but the file data/cognito-identity/2014-06-30/paginators-1.json.php is blank, so no paginators are implemented. I see NextToken in the response, but don't understand the pattern to seamlessly load more results (do (...) {} while (...)?)
I solved it like this:
$identities = [];
$i = $cognitoIdentityClient->listIdentities([
'IdentityPoolId' => IDENTITYPOOLID,
'MaxResults' => 60,
]);
$identities = array_merge($identities, $i->get('Identities'));
while ($nextToken = $i->get('NextToken')) {
$i = $cognitoIdentityClient->listIdentities([
'IdentityPoolId' => IDENTITYPOOLID,
'MaxResults' => 60,
'NextToken' => $nextToken,
]);
$identities = array_merge($identities, $i->get('Identities'));
}

YII2 error - The "id" configuration for the Application is required

I'm trying to start with YII2 (I should say that quite difficult after ASP.NET MVC) and got this error, but can't get what's wrong - id property has been set.
<?php
return [
'id' => 'crmapp',
'basePath' => realpath(__DIR__ . '/../'),
'components' => [
'request' => [
'cookieValidationKey' => 'somekey'
],
'urlManager'=>[
'enablePrettyUrl'=>true,
'showScriptName'=>false
]
],
'db'=> [
require(__DIR__.'/db.php'),
]];
Here is full error text:
Fatal error: Uncaught exception 'yii\base\InvalidConfigException' with message 'The "id" configuration for the Application is required.' in C:\xampp\htdocs\crmapp\vendor\yiisoft\yii2\base\Application.php:220 Stack trace: #0 C:\xampp\htdocs\crmapp\vendor\yiisoft\yii2\base\Application.php(202): yii\base\Application->preInit('C:\\xampp\\htdocs...') #1 C:\xampp\htdocs\crmapp\web\index.php(10): yii\base\Application->__construct('C:\\xampp\\htdocs...') #2 {main} thrown in C:\xampp\htdocs\crmapp\vendor\yiisoft\yii2\base\Application.php on line 220
Here is web/index.php
<?php
require(__DIR__.'/../vendor/yiisoft/yii2/Yii.php');
$config = (__DIR__.'/../config/web.php');
(new yii\web\Application($config))->run();
Here's your problem:
$config = (__DIR__.'/../config/web.php');
$config contains the path to web.php, not its contents. It should be:
$config = require(__DIR__ . '/../config/web.php');

Write username to httpheader for web service authetification with php

My code:
$url = "http://x.x.x.x/ws/special/Service?wsdl";
$context = stream_context_create(array('http' => array( 'username' => "jonas" )));
$client = new SoapClient($url, array("trace" => 1, "exception" => 0));
$res = $client->__soapCall("getinfo",array('counter'=>'10'));
Error:-
Fatal error: Uncaught SoapFault exception: [S:Server] missing parameter
'username' in C:\xampp\htdocs\test.php:7 Stack trace: #0
C:\xampp\htdocs\test.php(7): SoapClient->__soapCall('getAsinfo...', Array)
#1 {main} thrown in C:\xampp\htdocs\test.php on line 7
How to write to http header?

Categories