caseyamcl / guzzle_retry_middleware

Middleware for Guzzle v6/7+ that automatically retries HTTP requests on 429, 503 responses.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

InvalidArgumentException: URI must be a string or UriInterface

umpirsky opened this issue · comments

After pushing GuzzleRetryMiddleware with max_retry_attempts: 3, retry_on_timeout: true, I get:

InvalidArgumentException:
URI must be a string or UriInterface

  at vendor/guzzlehttp/psr7/src/functions.php:62
  at GuzzleHttp\Psr7\uri_for(object(Closure))
     (vendor/guzzlehttp/guzzle/src/Client.php:144)
  at GuzzleHttp\Client->buildUri(object(Closure), array('synchronous' => true, 'timeout' => 2.0, 'base_uri' => object(Uri), 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => 5, 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false, '_conditional' => array('X-Api-Key' => '***', 'User-Agent' => 'GuzzleHttp/6.3.3 curl/7.60.0 PHP/7.2.11')))
     (vendor/guzzlehttp/guzzle/src/Client.php:117)
  at GuzzleHttp\Client->requestAsync('push', object(Closure), array('synchronous' => true, 'timeout' => 2.0, 'base_uri' => object(Uri), 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => 5, 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false, '_conditional' => array('X-Api-Key' => '***', 'User-Agent' => 'GuzzleHttp/6.3.3 curl/7.60.0 PHP/7.2.11')))
     (vendor/guzzlehttp/guzzle/src/Client.php:131)
  at GuzzleHttp\Client->request('push', object(Closure), array('synchronous' => true))
     (vendor/guzzlehttp/guzzle/src/Client.php:89)

It works without GuzzleRetryMiddleware.

php composer.phar show | grep guzzle
caseyamcl/guzzle_retry_middleware   v2.2                             Guzzle middleware that handles HTTP Retry-After middleware
guzzlehttp/guzzle                   6.3.3                            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 m...
php-http/guzzle6-adapter            v1.1.1                           Guzzle 6 HTTP Adapter

It was the issue in my code, sorry for the noise.

@umpirsky glad to hear you got it worked out!

Hey @umpirsky I'm facing the same issue in one of my unit tests.. Could you tell me how you figured this out?

Sorry, can't remember, it was more then a year ago.

Hey @soheb-somani... author here! If you'll provide more details on the context, I'll try to help out.

When encountering this issue, try double-checking what are you passing in as variable. When I encountered this, the configuration in the environment that was failing passed null instead of a URL.