简体   繁体   中英

Neo4j PHP Graphaware '415 Unsupported Media Type '

The following test case (assuming correct password)


    <?php
    require 'vendor/autoload.php';
    
    use GraphAware\Neo4j\Client\ClientBuilder;
    
        $client = ClientBuilder::create()
        ->addConnection('default','http://neo4j:neo4j@localhost:7474')
        ->build();
    
        $result = $client->run('match (n:person) return n');

gives me the following error:


Fatal error: Uncaught Http\Client\Common\Exception\ClientErrorException: Unsupported Media Type in C:\Users\Ali\Desktop\Xamp\htdocs\Neo4j\vendor\php-http\client-common\src\Plugin\ErrorPlugin.php:72 Stack trace: #0 C:\Users\Ali\Desktop\Xamp\htdocs\Neo4j\vendor\php-http\client-common\src\Plugin\ErrorPlugin.php(54):HttpClientCommonPluginErrorPlugin->transformResponseToException(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 C:\Users\Ali\Desktop\Xamp\htdocs\Neo4j\vendor\php-http\httplug\src\Promise\HttpFulfilledPromise.php(34): Http\Client\Common\Plugin\ErrorPlugin->Http\Client\Common\Plugin\{closure}(Object(GuzzleHttp\Psr7\Response)) #2 C:\Users\Ali\Desktop\Xamp\htdocs\Neo4j\vendor\php-http\client-common\src\Plugin\ErrorPlugin.php(55): Http\Client\Promise\HttpFulfilledPromise->then(Object(Closure)) #3 C:\Users\Ali\Desktop\Xamp\htdocs\Neo4j\vendor\php-http\client-common\src\PluginClient.php(161): Http\Client\Common\Plugin\ErrorPlugin->handleRequest(Object(GuzzleHttp\Psr7\Request), Object(Closure), in C:\Users\Ali\Desktop\Xamp\htdocs\Neo4j\vendor\php-http\client-common\src\Plugin\ErrorPlugin.php on line 72

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?

I see the same problem:(

I debugged it into HttpDriver/Session.php flush function and I think headers are set up incorrectly:

public function flush(Pipeline $pipeline)
    {
        $request = $this->prepareRequest($pipeline);
        try {
            $response = $this->httpClient->sendRequest($request);

value of request
[headers:GuzzleHttp\Psr7\Request:private] => Array
        (
            [Host] => Array
                (
                    [0] => localhost:7474
                )

            [0] => Array
                (
                    [X-Stream] => 1
                    [Content-Type] => application/json
                )

        )

Pretty sure the request should be like this:

Array
        (
            [Host] => Array
                (
                    [0] => localhost:7474
                )
            [X-Stream] => 1
            [Content-Type] => application/json
        )

To fix this I modified PrepareRequst function to generate correct headers

// Line 197
$headers = [
  'X-Stream' => true,
  'Content-Type' => 'application/json'
];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM