Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j PHP Graphaware '400 Bad Content-Type header' error

The following test case (assuming correct password)

<?php
    require_once "vendor/autoload.php";
    use GraphAware\Neo4j\Client\ClientBuilder;
    $client = ClientBuilder :: create() -> addConnection("default", "http://neo4j:Password@localhost:7474") -> build();
    $query  = "MATCH (u:User)
               RETURN u";
    $result = $client -> run($query);
    $user = $result -> firstRecord() -> values()[0];
?>

gives me the following error:

PHP Fatal error:  Uncaught GuzzleHttp\\Exception\\ClientException: Client error: `POST http://neo4j:***@localhost:7474/db/data/transaction/commit` resulted in a `400 Bad Content-Type header value: ''` response in /var/www/html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /var/www/html/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\\Exception\\RequestException::create(Object(GuzzleHttp\\Psr7\\Request), Object(GuzzleHttp\\Psr7\\Response))
#1 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\\Middleware::GuzzleHttp\\{closure}(Object(GuzzleHttp\\Psr7\\Response))
#2 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\\Promise\\Promise::callHandler(1, Object(GuzzleHttp\\Psr7\\Response), Array)
#3 /var/www/html/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\\Promise\\Promise::GuzzleHttp\\Promise\\{closure}()
#4 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(246): GuzzleHttp\\Promise\\TaskQueue->run(true)
#5 /var/www/html/vendor/guzzlehttp/ in /var/www/html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113, referer: http://localhost/

This is the $client when I var_dump it:

object(GraphAware\Neo4j\Client\Client)#7 (2) {
  ["connectionManager":protected]=>
  object(GraphAware\Neo4j\Client\Connection\ConnectionManager)#2 (2) {
    ["connections":"GraphAware\Neo4j\Client\Connection\ConnectionManager":private]=>
    array(1) {
      ["default"]=>
      object(GraphAware\Neo4j\Client\Connection\Connection)#4 (5) {
        ["alias":"GraphAware\Neo4j\Client\Connection\Connection":private]=>
        string(7) "default"
        ["uri":"GraphAware\Neo4j\Client\Connection\Connection":private]=>
        string(38) "http://neo4j:Password@localhost:7474"
        ["driver":"GraphAware\Neo4j\Client\Connection\Connection":private]=>
        object(GraphAware\Neo4j\Client\HttpDriver\Driver)#6 (2) {
          ["uri":protected]=>
          string(38) "http://neo4j:Password@localhost:7474"
          ["config":protected]=>
          object(GraphAware\Neo4j\Client\HttpDriver\Configuration)#5 (1) {
            ["timeout":protected]=>
            int(5)
          }
        }
        ["session":"GraphAware\Neo4j\Client\Connection\Connection":private]=>
        NULL
        ["timeout":"GraphAware\Neo4j\Client\Connection\Connection":private]=>
        int(5)
      }
    }
    ["master":"GraphAware\Neo4j\Client\Connection\ConnectionManager":private]=>
    NULL
  }
  ["eventDispatcher":protected]=>
  object(Symfony\Component\EventDispatcher\EventDispatcher)#8 (2) {
    ["listeners":"Symfony\Component\EventDispatcher\EventDispatcher":private]=>
    array(0) {
    }
    ["sorted":"Symfony\Component\EventDispatcher\EventDispatcher":private]=>
    array(0) {
    }
  }
}

I don't know how to interpret this or what is wrong.

  • My database is running properly in the neo4j browser client.

  • As far as I know graphaware is installed appropriately, as per the instructions on the website.

  • I have tested and the error occurs at the point of running the query, not at the point of creating the client (even though this is not indicated clearly by the error).

  • If I copy / paste the query directly into the neo4j browser client then it works as expected.

Any idea why I am getting this error?

like image 751
Stephanos Papastylianou Avatar asked Oct 17 '22 13:10

Stephanos Papastylianou


1 Answers

According to GraphAware PHP Client you don't seem to use the latest version, so you need to update, OR you hit the empty array bug (e.g. Your problem is that you don't send Content-Type:application/json, that seems to only be set using function prepareRequest in GraphAware\Neo4j\Client\HttpDriver\Session). Also look at your query syntax since it seems to be deprecated in Install instructions and in the developer documentation for Neo4j.

like image 172
Gillsoft AB Avatar answered Oct 27 '22 19:10

Gillsoft AB