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

Could not read 4 bytes from sandbox.evernote.com #15

Open
vb2005xu opened this issue Jul 1, 2015 · 5 comments
Open

Could not read 4 bytes from sandbox.evernote.com #15

vb2005xu opened this issue Jul 1, 2015 · 5 comments

Comments

@vb2005xu
Copy link

vb2005xu commented Jul 1, 2015

all sample code , i had get that error! , please tell me how to solve it, 3q!

Fatal error: Uncaught exception 'Thrift\Exception\TTransportException' with message 'THttpClient: Could not read 4 bytes from sandbox.evernote.com:443//edam/user' in E:\ken_dev\xiche_c_apihelper\app\g\evernote\Thrift\Transport\THttpClient.php:162 Stack trace: #0 E:\ken_dev\xiche_c_apihelper\app\g\evernote\Thrift\Transport\TTransport.php(74): Thrift\Transport\THttpClient->read(4) #1 E:\ken_dev\xiche_c_apihelper\app\g\evernote\Thrift\Protocol\TBinaryProtocol.php(305): Thrift\Transport\TTransport->readAll(4) #2 E:\ken_dev\xiche_c_apihelper\app\g\evernote\Thrift\Protocol\TBinaryProtocol.php(197): Thrift\Protocol\TBinaryProtocol->readI32(NULL) #3 E:\ken_dev\xiche_c_apihelper\app\g\evernote\EDAM\UserStore\UserStore.php(710): Thrift\Protocol\TBinaryProtocol->readMessageBegin(NULL, 0, 0) #4 E:\ken_dev\xiche_c_apihelper\app\g\evernote\EDAM\UserStore\UserStore.php(679): EDAM\UserStore\UserStoreClient->recv_getNoteStoreUrl() #5 [internal function]: EDAM\UserStore\UserStoreClient->getNoteStoreUrl('S=s1:U=91183:E=...') #6 E:\ken_dev\x in E:\ken_dev\xiche_c_apihelper\app\g\evernote\Thrift\Transport\THttpClient.php on line 162
@Laurent-Sarrazin
Copy link
Contributor

Please provide more information :

  • environment ? OS ? Version ?
  • phpinfo
  • how did you install the sdk ? with composer ?

@vb2005xu
Copy link
Author

vb2005xu commented Jul 1, 2015

env

PHP 5.5.23 (cli) (built: Mar 23 2015 01:47:37) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies

$ php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
igbinary
intl
json
ldap
libxml
mbstring
mhash
mysql
mysqli
mysqlnd
odbc
openssl
pcntl
pcre
PDO
pdo_mysql
PDO_ODBC
pdo_sqlite
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib

[Zend Modules]

error:


PHP Fatal error:  Uncaught exception 'Thrift\Exception\TTransportException' with message 'THttpClient: Could not read 4 bytes from sandbox.evernote.com:443/edam/user' in /usr/local/var/www/xiche_c_apihelper/app/g/evernote/Thrift/Transport/THttpClient.php:163
Stack trace:
#0 /usr/local/var/www/xiche_c_apihelper/app/g/evernote/Thrift/Transport/TTransport.php(74): Thrift\Transport\THttpClient->read(4)
#1 /usr/local/var/www/xiche_c_apihelper/app/g/evernote/Thrift/Protocol/TBinaryProtocol.php(305): Thrift\Transport\TTransport->readAll(4)
#2 /usr/local/var/www/xiche_c_apihelper/app/g/evernote/Thrift/Protocol/TBinaryProtocol.php(197): Thrift\Protocol\TBinaryProtocol->readI32(NULL)
#3 /usr/local/var/www/xiche_c_apihelper/app/g/evernote/EDAM/UserStore/UserStore.php(710): Thrift\Protocol\TBinaryProtocol->readMessageBegin(NULL, 0, 0)
#4 /usr/local/var/www/xiche_c_apihelper/app/g/evernote/EDAM/UserStore/UserStore.php(679): EDAM\UserStore\UserStoreClient->recv_getNoteStoreUrl()
#5 [internal function]: EDAM\UserStore\UserStoreClient->getNot in /usr/local/var/www/xiche_c_apihelper/app/g/evernote/Thrift/Transport/THttpClient.php on line 163

mytest code

$token = 'S=s1:U=91183:E=155a102c369:C=14e49519440:P=81:A=vb2005xu:V=2:H=fbc6ab62a89ce94507e52a575ecb552c';
$sandbox = true;
$advancedClient = new \Evernote\AdvancedClient($token, $sandbox);

$noteStore = $advancedClient->getNoteStore();
$notebooks = $noteStore->listNotebooks();
prety_printr($notebooks,'--------------');exit;

i have print the error in file Thrift/Transport/THttpClient.php ,this is my modify

<?php
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 * @package thrift.transport
 */

namespace Thrift\Transport;

use Thrift\Transport\TTransport;
use Thrift\Exception\TTransportException;
use Thrift\Factory\TStringFuncFactory;

/**
 * HTTP client for Thrift
 *
 * @package thrift.transport
 */
class THttpClient extends TTransport {

  /**
   * The host to connect to
   *
   * @var string
   */
  protected $host_;

  /**
   * The port to connect on
   *
   * @var int
   */
  protected $port_;

  /**
   * The URI to request
   *
   * @var string
   */
  protected $uri_;

  /**
   * The scheme to use for the request, i.e. http, https
   *
   * @var string
   */
  protected $scheme_;

  /**
   * Buffer for the HTTP request data
   *
   * @var string
   */
  protected $buf_;

  /**
   * Input socket stream.
   *
   * @var resource
   */
  protected $handle_;

  /**
   * Read timeout
   *
   * @var float
   */
  protected $timeout_;

  /**
   * http headers
   *
   * @var array
   */
  protected $headers_;

  /**
   * Make a new HTTP client.
   *
   * @param string $host
   * @param int    $port
   * @param string $uri
   */
  public function __construct($host, $port=80, $uri='', $scheme = 'http') {
    // if ((TStringFuncFactory::create()->strlen($uri) > 0) && ($uri{0} != '/')) {
    //   $uri = '/'. $uri;
    // }
    $uri = '/'. ltrim($uri,'/');
    $this->scheme_ = $scheme;
    $this->host_ = $host;
    $this->port_ = $port;
    $this->uri_ = $uri;
    $this->buf_ = '';
    $this->handle_ = null;
    $this->timeout_ = null;
    $this->headers_ = array();
  }

  /**
   * Set read timeout
   *
   * @param float $timeout
   */
  public function setTimeoutSecs($timeout) {
    $this->timeout_ = $timeout;
  }

  /**
   * Whether this transport is open.
   *
   * @return boolean true if open
   */
  public function isOpen() {
    return true;
  }

  /**
   * Open the transport for reading/writing
   *
   * @throws TTransportException if cannot open
   */
  public function open() {}

  /**
   * Close the transport.
   */
  public function close() {
    if ($this->handle_) {
      @fclose($this->handle_);
      $this->handle_ = null;
    }
  }

  /**
   * Read some data into the array.
   *
   * @param int    $len How much to read
   * @return string The data that has been read
   * @throws TTransportException if cannot read any more data
   */
  public function read($len) {
    $data = fread($this->handle_, $len);var_dump($len,$data);echo "\n";
    if ($data === FALSE || $data === '') {
      $md = stream_get_meta_data($this->handle_);
      if ($md['timed_out']) {
        throw new TTransportException('THttpClient: timed out reading '.$len.' bytes from '.$this->host_.':'.$this->port_.$this->uri_, TTransportException::TIMED_OUT);
      } else {
        throw new TTransportException('THttpClient: Could not read '.$len.' bytes from '.$this->host_.':'.$this->port_.$this->uri_, TTransportException::UNKNOWN);
      }
    }
    return $data;
  }

  /**
   * Writes some data into the pending buffer
   *
   * @param string $buf  The data to write
   * @throws TTransportException if writing fails
   */
  public function write($buf) {
    $this->buf_ .= $buf;
  }

  /**
   * Opens and sends the actual request over the HTTP connection
   *
   * @throws TTransportException if a writing error occurs
   */
  public function flush() {
    // God, PHP really has some esoteric ways of doing simple things.
    $host = $this->host_.($this->port_ != 80 ? ':'.$this->port_ : '');

    $headers = array();
    $defaultHeaders = array('Host' => $host,
                            'Accept' => 'application/x-thrift',
                            'User-Agent' => 'PHP/THttpClient',
                            'Content-Type' => 'application/x-thrift',
                            'Content-Length' => TStringFuncFactory::create()->strlen($this->buf_));
    foreach (array_merge($defaultHeaders, $this->headers_) as $key => $value) {
        $headers[] = "$key: $value";
    }
// prety_printr($this);exit;
    $options = array('method' => 'POST',
                     'header' => implode("\r\n", $headers),
                     'max_redirects' => 1,
                     'content' => $this->buf_);
    if ($this->timeout_ > 0) {
      $options['timeout'] = $this->timeout_;
    }
    $this->buf_ = '';

    $contextid = stream_context_create(array('http' => $options));
    stream_context_set_option ( $contextid, 'ssl', 'verify_peer', false );

    // $file = file_get_contents($this->scheme_.'://'.$host.$this->uri_, false, $contextid);
    // echo $file;
    // echo "\n\t";
    // exit;

    $this->handle_ = fopen($this->scheme_.'://'.$host.$this->uri_, 'r', false, $contextid);
// var_dump($this->handle_);exit;
var_dump($this->scheme_.'://'.$host.$this->uri_);echo "\n";
    // Connect failed?
    if ($this->handle_ === FALSE) {
      $this->handle_ = null;
      $error = 'THttpClient: Could not connect to '.$host.$this->uri_;
      throw new TTransportException($error, TTransportException::NOT_OPEN);
    }
  }

  public function addHeaders($headers) {
    $this->headers_ = array_merge($this->headers_, $headers);
  }

}

this is print result:

localhost:xiche_c_apihelper xiaohanxu$ php cli.php pathinfo=/index/evernote/books.json
string(42) "https://sandbox.evernote.com:443/edam/user"

int(4)
string(4) "?"

int(4)
string(4) ""

int(15)
string(15) "getNoteStoreUrl"

int(4)
string(4) ""

int(1)
string(1) "
           "

int(2)
string(2) ""

int(4)
string(4) "/"

int(47)
string(47) "https://sandbox.evernote.com/shard/s1/notestore"

int(1)
string(1) ""

int(4)
string(0) ""

PHP Fatal error:  Uncaught exception 'Thrift\Exception\TTransportException' with message 'THttpClient: Could not read 4 bytes from sandbox.evernote.com:443/edam/user' in /usr/local/var/www/xiche_c_apihelper/app/g/evernote/Thrift/Transport/THttpClient.php:163
Stack trace:
#0 /usr/local/var/www/xiche_c_apihelper/app/g/evernote/Thrift/Transport/TTransport.php(74): Thrift\Transport\THttpClient->read(4)
#1 /usr/local/var/www/xiche_c_apihelper/app/g/evernote/Thrift/Protocol/TBinaryProtocol.php(305): Thrift\Transport\TTransport->readAll(4)
#2 /usr/local/var/www/xiche_c_apihelper/app/g/evernote/Thrift/Protocol/TBinaryProtocol.php(197): Thrift\Protocol\TBinaryProtocol->readI32(NULL)
#3 /usr/local/var/www/xiche_c_apihelper/app/g/evernote/EDAM/UserStore/UserStore.php(710): Thrift\Protocol\TBinaryProtocol->readMessageBegin(NULL, 0, 0)
#4 /usr/local/var/www/xiche_c_apihelper/app/g/evernote/EDAM/UserStore/UserStore.php(679): EDAM\UserStore\UserStoreClient->recv_getNoteStoreUrl()
#5 [internal function]: EDAM\UserStore\UserStoreClient->getNot in /usr/local/var/www/xiche_c_apihelper/app/g/evernote/Thrift/Transport/THttpClient.php on line 163

Fatal error: Uncaught exception 'Thrift\Exception\TTransportException' with message 'THttpClient: Could not read 4 bytes from sandbox.evernote.com:443/edam/user' in /usr/local/var/www/xiche_c_apihelper/app/g/evernote/Thrift/Transport/THttpClient.php:163
Stack trace:
#0 /usr/local/var/www/xiche_c_apihelper/app/g/evernote/Thrift/Transport/TTransport.php(74): Thrift\Transport\THttpClient->read(4)
#1 /usr/local/var/www/xiche_c_apihelper/app/g/evernote/Thrift/Protocol/TBinaryProtocol.php(305): Thrift\Transport\TTransport->readAll(4)
#2 /usr/local/var/www/xiche_c_apihelper/app/g/evernote/Thrift/Protocol/TBinaryProtocol.php(197): Thrift\Protocol\TBinaryProtocol->readI32(NULL)
#3 /usr/local/var/www/xiche_c_apihelper/app/g/evernote/EDAM/UserStore/UserStore.php(710): Thrift\Protocol\TBinaryProtocol->readMessageBegin(NULL, 0, 0)
#4 /usr/local/var/www/xiche_c_apihelper/app/g/evernote/EDAM/UserStore/UserStore.php(679): EDAM\UserStore\UserStoreClient->recv_getNoteStoreUrl()
#5 [internal function]: EDAM\UserStore\UserStoreClient->getNot in /usr/local/var/www/xiche_c_apihelper/app/g/evernote/Thrift/Transport/THttpClient.php on line 163
localhost:xiche_c_apihelper xiaohanxu$ 

@vb2005xu
Copy link
Author

vb2005xu commented Jul 1, 2015

i try in windows7 and mac:

$ uname -a
Darwin localhost 14.1.1 Darwin Kernel Version 14.1.1: Thu Feb 26 22:41:49 PST 2015; root:xnu-2782.15.5~1/RELEASE_X86_64 x86_64

@vb2005xu
Copy link
Author

vb2005xu commented Jul 1, 2015

i can run that code only, but other example can not run !

    // First, get the right Store
$userStore = $advancedClient->getUserStore();

// Then do the call
$user = $userStore->getUser();
prety_printr($user,'--------------');exit;

@vb2005xu
Copy link
Author

vb2005xu commented Jul 3, 2015

没有人能够解决么?

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

No branches or pull requests

2 participants