Requests icon indicating copy to clipboard operation
Requests copied to clipboard

curl error #23

Open blizzardkem opened this issue 8 years ago • 6 comments

[root@zm lrg]# df -h Filesystem Size Used Avail Use% Mounted on /dev/ploop26002p1 59G 4.8G 52G 9% / devtmpfs 1.0G 0 1.0G 0% /dev tmpfs 1.0G 0 1.0G 0% /dev/shm tmpfs 1.0G 1.4M 1023M 1% /run tmpfs 1.0G 0 1.0G 0% /sys/fs/cgroup tmpfs 205M 0 205M 0% /run/user/0

...

Requests/Transport/cURL.php:406: cURL error 23: Failed writing body (958 != 1153)

wtf?

blizzardkem avatar May 02 '16 20:05 blizzardkem

function curl($url)
{
    $cl = curl_init();
    curl_setopt($cl, CURLOPT_URL, $url);
    curl_setopt($cl, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($cl, CURLOPT_HEADER, FALSE);
    curl_setopt($cl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($cl, CURLOPT_SSL_VERIFYHOST, FALSE);

    $ex = curl_exec($cl);
    curl_close($cl);

    return $ex;
}

It works without problems, but the @Requests did not want

blizzardkem avatar May 02 '16 21:05 blizzardkem

include 'classes/Requests.php';
Requests::register_autoloader();
$request = Requests::get('http://ya.ru');

///

[root@zm lrg]# php test.php
PHP Fatal error:  Uncaught exception 'Requests_Exception' with message 'cURL error 23: Failed writing body (255 != 261)' in /root/lrg/classes/Requests/Transport/cURL.php:406
Stack trace:
#0 /root/lrg/classes/Requests/Transport/cURL.php(177): Requests_Transport_cURL->process_response('<!DOCTYPE html>...', Array)
#1 /root/lrg/classes/Requests.php(367): Requests_Transport_cURL->request('https://ya.ru/', Array, NULL, Array)
#2 /root/lrg/classes/Requests.php(672): Requests::request('https://ya.ru/', Array, NULL, 'GET', Array)
#3 /root/lrg/classes/Requests.php(371): Requests::parse_response('HTTP/1.1 302 Fo...', 'http://ya.ru/', Array, NULL, Array)
#4 /root/lrg/classes/Requests.php(221): Requests::request('http://ya.ru', Array, NULL, 'GET', Array)
#5 /root/lrg/test.php(5): Requests::get('http://ya.ru')
#6 {main}
  thrown in /root/lrg/classes/Requests/Transport/cURL.php on line 406
[root@zm lrg]#

blizzardkem avatar May 02 '16 21:05 blizzardkem

[root@zm lrg]# php -v
PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

blizzardkem avatar May 11 '16 13:05 blizzardkem

The problem CURLOPT_HEADERFUNCTION / CURLOPT_WRITEFUNCTION That's earned:

    public function request($url, $headers = array(), $data = array(), $options = array()) {
...
        $data = curl_exec($this->handle);
        list($this->headers, $this->response_data) = explode("\r\n\r\n", $data, 2);
        $this->headers .= "\r\n\r\n";
        $this->response_bytes = strlen($this->response_data);
        $response = $this->response_data;
...
    }

    protected function setup_handle($url, $headers, $data, $options) {
...
/*
        if (true === $options['blocking']) {
            curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, array(&$this, 'stream_headers'));
            curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array(&$this, 'stream_body'));
            curl_setopt($this->handle, CURLOPT_BUFFERSIZE, Requests::BUFFER_SIZE);
        }
*/
...
    }

blizzardkem avatar May 11 '16 14:05 blizzardkem

Looks like this one is most likely caused by #244

dd32 avatar Oct 05 '16 03:10 dd32

I have the same problem with this code:

$requestResponse = Requests::get($urlRequest, $requestHeaders, $requestOptions); This request returns an exception with the message "cURL error 23: Failed writing body (1155 != 1160)"

In my php.ini the mbstring.func_overload is disabled.

The $urlRequest parameter is an url such as https://oms.7pixel.it/api/m/v1/orders/cancelled?token=<token string>

The attached file is the xml response expected. I suspect that the problem is due to cancelNote field who contains some chars not correctly parsed, because others requests with different response work fine.

I tried exactly the same request with curl from command line on the same server on which the application run and it works without any errors.

Any suggests?

response.txt

mcasu avatar Nov 29 '16 10:11 mcasu