troydavisson / PHRETS

PHP client library for interacting with a RETS server to pull real estate listings, photos and other data made available from an MLS system
http://troda.com
MIT License
451 stars 236 forks source link

Getting of `401 Unauthorized.` #189

Open alfchee opened 6 years ago

alfchee commented 6 years ago

Hi, I have seen that with some providers this problems occurs very often. In my case I want to fetch data from a Rapattoni connection and I'm looping through the multiple Classes of Property, then after finished the first download and making the second Search call the error appears:

connection stablishedconnected 
Query: (ListingRid=1+),(LastModifiedDateTime=2017-01-01T00:00:00-2017-01-16T00:00:00) 
Offset: 1 
Class: RESI 
fetching from RETS... 
Total: 1770 
[===============================] 100%  1770/1770 remaining: 0 sec.  elapsed: 328 sec.   

Query: (ListingRid=1+),(LastModifiedDateTime=2017-01-01T00:00:00-2017-01-16T00:00:00) 
Offset: 1 
Class: LOTL 
fetching from RETS... 
PHP Fatal error:  Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: `GET http://rets172lax.raprets.com:6103/xxxx/##/login.aspx` resulted in a `401 Unauthorized.` response:
<RETS ReplyCode="0" ReplyText="Operation successful." >
<RETS-RESPONSE>

This error only happens with this client because is the only connection with Rapattoni that we are making, and the support team answered that may be a second connection is closing the first established because they only allow 1 connection at time.

I'm using the version 2.5 because it seems to have some patches about the use of Cookies and also the re-login when session problems occurs, but I'm having the same bugs than with version 2.2

Then what can I do to solve this problem?

prospace7090 commented 6 years ago

Add \PHRETS\Http\Client::set(new \GuzzleHttp\Client); before creating Session like that:

\PHRETS\Http\Client::set(new \GuzzleHttp\Client);
$this->rets = new \PHRETS\Session( $this->config );
carenamaemanzano commented 6 years ago

Hi @prospace7090 ,

Where should we put that? What file exactly?

Thanks

steveheinsch commented 6 years ago

@carenamaemanzano He showed where in his post. Wherever in your code you are doing $this->rets = new \PHRETS\Session( $this->config ); add it right before that.