spotify-web-api-php icon indicating copy to clipboard operation
spotify-web-api-php copied to clipboard

cURL transport error: 7 Failed to connect to api.spotify.com port 443: Timed out in

Open omadepod opened this issue 3 years ago • 12 comments

Since about a year my scripts stop in the middle of my page with the curl transport error (see subject). I tried adding a sleep(1) command but it doesn't help much.

Many thanks

omadepod avatar Jan 12 '22 15:01 omadepod

Hi! Are you behind a firewall, proxy, or similar? That's usually the issue with these kind of errors.

jwilsson avatar Jan 12 '22 19:01 jwilsson

Hi!

I have windows firewall running but firefox is allowed there and i have orange internet for which i never need to use a proxy.

omadepod avatar Jan 12 '22 20:01 omadepod

Hmm, does it work connecting to any other URL. For example:

<?php
require 'vendor/autoload.php';

$request = new SpotifyWebAPI\Request();

var_dump($request->send('GET', 'https://example.com'));

jwilsson avatar Jan 13 '22 16:01 jwilsson

yes this works perfectly :

array(4) { ["body"]=> NULL ["headers"]=> array(13) { ["content-encoding"]=> string(4) "gzip" ["accept-ranges"]=> string(5) "bytes" ["age"]=> string(6) "465613" ["cache-control"]=> string(14) "max-age=604800" ["content-type"]=> string(24) "text/html; charset=UTF-8" ["date"]=> string(29) "Fri, 14 Jan 2022 12:12:20 GMT" ["etag"]=> string(17) ""3147526947+gzip"" ["expires"]=> string(29) "Fri, 21 Jan 2022 12:12:20 GMT" ["last-modified"]=> string(29) "Thu, 17 Oct 2019 07:18:26 GMT" ["server"]=> string(14) "ECS (dcb/7F15)" ["vary"]=> string(15) "Accept-Encoding" ["x-cache"]=> string(3) "HIT" ["content-length"]=> string(3) "648" } ["status"]=> int(200) ["url"]=> string(19) "https://example.com" }

my fatal error in my test script:

Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException: cURL transport error: 28 Failed to connect to api.spotify.com port 443: Timed out in C:_xampp\htdocs\system\spotify\src\Request.php:225 Stack trace: #0 C:_xampp\htdocs\system\spotify\src\Request.php(132): SpotifyWebAPI\Request->send('GET', 'https://api.spo...', 'limit=20&time_r...', Array) #1 C:_xampp\htdocs\system\spotify\src\SpotifyWebAPI.php(124): SpotifyWebAPI\Request->api('GET', '/v1/me/top/trac...', Array, Array) #2 C:_xampp\htdocs\system\spotify\src\SpotifyWebAPI.php(1227): SpotifyWebAPI\SpotifyWebAPI->sendRequest('GET', '/v1/me/top/trac...', Array) #3 C:_xampp\htdocs\system\spotify\src\SpotifyWebAPI.php(2105): SpotifyWebAPI\SpotifyWebAPI->getMyTop('tracks', Array) #4 C:_xampp\htdocs\includes\ajax_spotify.php(283): SpotifyWebAPI\SpotifyWebAPI->mycms_get_spotify_my_top('tracks', 'short_term') #5 {main} thrown in C:_xampp\htdocs\system\spotify\src\Request.php on line 225

omadepod avatar Jan 14 '22 12:01 omadepod

Have you tried increasing the timeout for cURL using the CURLOPT_CONNECTTIMEOUT, CURLOPT_TIMEOUT, or both of those options? if not, docs around that is available here. You also try setting the CURLOPT_CAINFO option to null and see if that makes any difference.

jwilsson avatar Jan 15 '22 13:01 jwilsson

with

protected $options = [ 'curl_options' => [CURLOPT_CONNECTTIMEOUT => 0, CURLOPT_TIMEOUT => 0], 'return_assoc' => false, ];

there's no difference

with

protected $options = [ 'curl_options' => [CURLOPT_CAINFO => null], 'return_assoc' => false, ];

i get this new error :

Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException: cURL transport error: 77 error setting certificate verify locations: CAfile: CApath: none in C:_xampp\htdocs\system\spotify\src\Request.php:225 Stack trace: #0 C:_xampp\htdocs\system\spotify\src\Request.php(110): SpotifyWebAPI\Request->send('POST', 'https://account...', 'grant_type=refr...', Array) #1 C:_xampp\htdocs\system\spotify\src\Session.php(204): SpotifyWebAPI\Request->account('POST', '/api/token', Array, Array) #2 C:_xampp\htdocs\system\spotify\src\class.omdp.spotify.php(55): SpotifyWebAPI\Session->refreshAccessToken('AQB4tGsSLV7mg8l...') #3 C:_xampp\htdocs\system\spotify\index.php(151): Spotify_api_access->mycms_get_spotify_connection() #4 {main} thrown in C:_xampp\htdocs\system\spotify\src\Request.php on line 225

omadepod avatar Jan 15 '22 14:01 omadepod

Hmm, which API method are you using when the error occurs? Does it work for other methods or is it always the same error?

I can't reproduce it locally and there's been a number of people with this kind of issue over the years but we've never been able to solve it, hence all the questions. I'm a but curious of what it could be and would like to find at least one solution to it 😄

jwilsson avatar Jan 16 '22 14:01 jwilsson

for example on this one :

$arr = $api->getMyTop("tracks", ["limit" => 2, "time_range" => "short_term"]); echo '

'.print_r( $arr, 1 ).'
'; exit();

omadepod avatar Jan 18 '22 23:01 omadepod

Can you try with another method? $api->me() for example. But you're able to get the access tokens correctly without any errors?

jwilsson avatar Jan 20 '22 19:01 jwilsson

$api->me(); gives the same error ... and no i don't get errors with the access tokens. [session:protected] => SpotifyWebAPI\Session Object is filled with information. The other fields in SpotifyWebAPI\SpotifyWebAPI Object are empty though.

omadepod avatar Jan 21 '22 17:01 omadepod

This is very strange. But you said you could access api.spotify.com using a browser, right? Could you also try the following:

  • Pinging api.spotify.com and see if that works.
  • Double check your hosts file to see that there's nothing in there pointing api.spotify.com somewhere else.

jwilsson avatar Jan 23 '22 16:01 jwilsson

I removed a bad ip i found somewhere on internet from my hosts file and now i have correct results with $api->me();

Seems like i get blocked when trying too much requests in my scripts. After a big script i get errors and can't even connect to my account but when i refresh it works again.

For example i want to find new releases from all my favourite artists so i need to query all my playlists, then albums from the artists and their date of release. Doing this gives the original Failed to connect to api.spotify.com port 443: Timed out error.

omadepod avatar Mar 13 '22 20:03 omadepod