Client error response [url] Unathorized

470 views
Skip to first unread message

Santiagazo Lara

unread,
Mar 1, 2017, 7:27:51 PM3/1/17
to PHRETS
I am also getting an error using Laravel 5.2/ Guzzle 5.*/ and PHRETS 2.* my error reads...

ClientException in RequestException.php line 89:Client error response [url] http://rets18.utahrealestate.com/contact/rets/login [status code] 401 [reason phrase] Unauthorized


Followed by the stack trace of:

  1. in RequestException.php line 89
  2. at RequestException::create(object(Request), object(Response)) in HttpError.php line 32
  3. at HttpError->onComplete(object(CompleteEvent), 'complete') in Emitter.php line 108
  4. at Emitter->emit('complete', object(CompleteEvent)) in RequestFsm.php line 91
  5. at RequestFsm->__invoke(object(Transaction)) in RequestFsm.php line 132
  6. at RequestFsm->GuzzleHttp\{closure}(array('transfer_stats' => array('url' => 'http://rets18.utahrealestate.com/contact/rets/login', 'content_type' => null, 'http_code' => '401', 'header_size' => '920', 'request_size' => '592', 'filetime' => '-1', 'ssl_verify_result' => '0', 'redirect_count' => '1', 'total_time' => '0.181026', 'namelookup_time' => '2.0E-5', 'connect_time' => '2.0E-5', 'pretransfer_time' => '0.000106', 'size_upload' => '0', 'size_download' => '0', 'speed_download' => '0', 'speed_upload' => '0', 'download_content_length' => '0', 'upload_content_length' => '-1', 'starttransfer_time' => '0.040061', 'redirect_time' => '0.140925', 'redirect_url' => '', 'primary_ip' => '52.10.117.248', 'certinfo' => array(), 'primary_port' => '80', 'local_ip' => '192.168.1.25', 'local_port' => '48562', 'error' => '', 'errno' => '0'), 'curl' => array('error' => '', 'errno' => '0'), 'effective_url' => 'http://rets18.utahrealestate.com/contact/rets/login', 'headers' => array('Server' => array('Apache-Coyote/1.1'), 'Set-Cookie' => array('JSESSIONID=9E79B99BFF8E37A684AF44794C6BC1B1; Path=/contact/; HttpOnly', 'JSESSIONID=9E79B99BFF8E37A684AF44794C6BC1B1; Path=/contact'), 'MIME-Version' => array('1.0'), 'Cache-Control' => array('private'), 'RETS-Version' => array('RETS/1.8'), 'WWW-Authenticate' => array('Digest realm="re...@retsiq.com",qop="auth",nonce="9439bd8fea374c43d5677e52d0536c45", opaque="acb5268616208"'), 'Content-Length' => array('0'), 'Date' => array('Wed, 01 Mar 2017 21:34:10 GMT')), 'version' => '1.1', 'status' => '401', 'reason' => 'Unauthorized', 'body' => resource)) in FulfilledPromise.php line 25
  7. at FulfilledPromise->then(object(Closure), nullnull) in CompletedFutureValue.php line 55
  8. at CompletedFutureValue->then(object(Closure), nullnull) in FutureResponse.php line 43
  9. at FutureResponse::proxy(object(CompletedFutureArray), object(Closure)) in RequestFsm.php line 134
  10. at RequestFsm->__invoke(object(Transaction)) in Client.php line 165
  11. at Client->send(object(Request)) in Client.php line 125
  12. at Client->get('http://rets18.utahrealestate.com/contact/rets/login', array('headers' => array('User-Agent' => 'PHRETS/2.0', 'RETS-Version' => 'RETS/1.8', 'Accept-Encoding' => 'gzip', 'Accept' => '*/*'), 'cookies' => object(CookieJar))) in Session.php line 361
  13. at Session->request('Login') in Session.php line 93
  14. at Session->Login() in IDXController.php line 25
  15. at IDXController->getLogin(object(Request))
When I go in to the Session.php file I find that it's all boiling down to the Guzzle call on line 360:
 $response = $this->client->get($url, $options);

when I dump&die each of these items as so...
dd($url, $options, $this->client);
this is my response:
"http://rets18.utahrealestate.com/contact/rets/login"
-----------
array:2 [
  "headers" => array:4 [
    "User-Agent" => "PHRETS/2.0"
    "RETS-Version" => "RETS/1.8"
    "Accept-Encoding" => "gzip"
    "Accept" => "*/*"
  ]
  "cookies" => CookieJar {#615 ▼
    -cookies: []
    -strictMode: false
  }
]
-----------
Client {#602 ▼
  -messageFactory: MessageFactory {#604 ▶}
  -baseUrl: Url {#603 ▼
    -scheme: ""
    -host: ""
    -port: null
    -username: null
    -password: null
    -path: ""
    -fragment: null
    -query: null
  }
  -defaults: array:6 [
    "allow_redirects" => true
    "exceptions" => true
    "decode_content" => true
    "verify" => true
    "headers" => array:4 [
      "User-Agent" => "PHRETS/2.0"
      "RETS-Version" => "RETS/1.8"
      "Accept-Encoding" => "gzip"
      "Accept" => "*/*"
    ]
    "auth" => array:3 [
      0 => "myUserName"
      1 => "myPassword"
      2 => "digest"
    ]
  ]
  -fsm: RequestFsm {#614 ▶}
  -emitter: null
}

It looks to me like everything is here but it all breaks if I let line 360 ($response = $this->client->get($url, $options);) execute.
Any ideas???

Santiagazo Lara

unread,
Mar 2, 2017, 4:37:41 PM3/2/17
to PHRETS
It would appear I solved the problem form some code I found posted in another part of this forum...
These 6 lines of code fixed it for me...

      $rets->getClient()->setDefaultOption(
            'config',
            [
                'curl' => [ CURLOPT_COOKIEFILE => tempnam('/tmp', 'phrets') ]
            ]
        );

It would appear that I was unable to set my cookie jar until I added this code. I placed it just before my $rets->login();

Hope it helps anyone struggling with similar issue.

Troy Davisson

unread,
Mar 10, 2017, 10:37:37 PM3/10/17
to PHRETS

Thank you for this post.  I'd identified a possible solution to this issue but it was much, much uglier than this.

This fixed https://github.com/troydavisson/PHRETS/issues/62 and probably at least one other.  I've pushed a commit to the 2.3 dev branch with this.

Thanks again!


--
You received this message because you are subscribed to the Google Groups "PHRETS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phrets+un...@googlegroups.com.
To post to this group, send email to phr...@googlegroups.com.
Visit this group at https://groups.google.com/group/phrets.
For more options, visit https://groups.google.com/d/optout.

Kirby Vandivort

unread,
Oct 21, 2017, 8:24:40 PM10/21/17
to PHRETS
Hi,

Had a perfectly working script until today, when I decided to update my Debian install to 9/Stretch.   The new Debian decided to make php 7 the default, and that has caused all kinds of problems for me.  But I'll only talk about PHRETS here.  :)

I'm now getting a 401 unauthorized.

PHP Fatal error:  Uncaught GuzzleHttp\Exception\ClientException: Client error: `GET http://connectmls-rets.mredllc.com/rets/server/login` resulted in a `401 Unauthorized` response in /home/kvandivo/rets/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /home/kvandivo/rets/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /home/kvandivo/rets/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /home/kvandivo/rets/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 /home/kvandivo/rets/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 /home/kvandivo/rets/vendor/guzzlehttp/promises/src/Promise.php(246): GuzzleHttp\Promise\TaskQueue->run(true)
#5 /home/kvandivo/rets/vendor/guzzlehttp/promises/src/Promise.php(223): GuzzleHttp\Promise\Promise->invokeWaitFn()
#6 /home/kvandivo/rets/vendor/guzzlehttp/promises/src/Promise.php(267): GuzzleHttp\Promise\Promise->waitIfPending()
#7 /home/kvandivo/rets/vendor/guzzlehttp/promises/src/Promise.php(225): GuzzleHttp\Promise\Promise->invokeWaitList()
#8 /home/kvandivo/rets/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
#9 /home/kvandivo/rets/vendor/guzzlehttp/guzzle/src/Client.php(131): GuzzleHttp\Promise\Promise->wait()
#10 /home/kvandivo/rets/vendor/troydavisson/phrets/src/Session.php(337): GuzzleHttp\Client->request('GET', 'http://connectm...', Array)
#11 /home/kvandivo/rets/vendor/troydavisson/phrets/src/Session.php(74): PHRETS\Session->request('Login')
#12 /home/kvandivo/rets/updateData.php(35): PHRETS\Session->Login()
#13 {main}
  thrown in /home/kvandivo/rets/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113


source code is basically the example....

date_default_timezone_set('UTC');

require_once("vendor/autoload.php");


$config = new \PHRETS\Configuration;

$config->setLoginUrl('http://connectmls-rets.mredllc.com/rets/server/login')

       ->setUsername('yes')

       ->setPassword('youbet')

       ->setRetsVersion('1.7');


$rets = new \PHRETS\Session($config);


$connect = $rets->Login();



output from composer....

~/rets>composer info

doctrine/inflector        v1.2.0  Common String Manipulations with regard to casing and singular/plural rules.

guzzlehttp/guzzle         6.3.0   Guzzle is a PHP HTTP client library

guzzlehttp/promises       v1.3.1  Guzzle promises library

guzzlehttp/psr7           1.4.2   PSR-7 message implementation that also provides common utility methods

illuminate/container      v5.5.17 The Illuminate Container package.

illuminate/contracts      v5.5.17 The Illuminate Contracts package.

illuminate/support        v5.5.17 The Illuminate Support package.

league/csv                9.1.0   Csv data manipulation made easy in PHP

nesbot/carbon             1.22.1  A simple API extension for DateTime.

psr/container             1.0.0   Common Container Interface (PHP FIG PSR-11)

psr/http-message          1.0.1   Common interface for HTTP messages

psr/simple-cache          1.0.0   Common interfaces for simple caching

symfony/polyfill-mbstring v1.6.0  Symfony polyfill for the Mbstring extension

symfony/translation       v3.3.10 Symfony Translation Component

troydavisson/phrets       2.4     RETS library in PHP



I've tried adding in the curl cookie code and various other random things, but I'm still getting this unauthorized exception.  I've got the php.ini files matching wrt the previous versions, so I'm not sure where I should start digging into this more.  Any guidance is appreciated.

Thanks!

Kirby Vandivort
Reply all
Reply to author
Forward
0 new messages