A little background first: for some reason, making curl calls inside my Vagrant machine works only if I use --tlsv1.2 option, without that I get:
cURL error 35: SSL connect error (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
So I've put that value into configuration file, ~/.curlrc, so every time I run
curl https://myapi.com on the command line that option is used automatically, and it works fine.
However, I am currently playing with Guzzle 6, which uses curl to make API calls in the background. I assumed that curl that Guzzle uses will use the same configuration file ~/.curlrc, but seems not because I'm getting again: cURL error 35: SSL connect error.
This is the code that I'm using:
$client = new HttpClient(['defaults' => [
'verify' => false
]]);
$response = $client->request('GET', 'https://myapi.com', ['curl' => [
CURLOPT_SSLVERSION => 6,
]]);
As you can see, I even tried to pass TLSV1.2 value(value 6 is mapped to TLSV1.2 according to curl php documentation) to curl, but still nothing. Anybodu have an idea what could be wrong here?
EDIT: yeah, just confirmed that Guzzle uses some other curl binary. I moved the original one to another location and can't no longer accessed it from the command line, but after that Guzzle still returns the same error.
Related
Now I am using coinbase/coinbase php library in laravel project. I tried to get accounts using $client->getAccounts();, But this gives error like following.
Symfony \ Component \ Debug \ Exception \ FatalThrowableError
(E_RECOVERABLE_ERROR) Argument 1 passed to
Coinbase\Wallet\Exception\HttpException::exceptionClass() must be an
instance of Psr\Http\Message\ResponseInterface, null given, called in
core\vendor\coinbase\coinbase\src\Exception\HttpException.php
on line 33
I tried to get error response by checking exception.
cURL error 60: SSL certificate problem: unable to get local issuer
certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
This code is normal and it was working 1 year ago without any issue.
Is there anyone for this issue?
Thank you for everyone's response here.
Try Uploading to Your online server and retry, it might be an issue with Your localhost.
I have experienced it sometime ago, but still fix, I will just upload to my cPanel and try it in production and it will work.
You are getting the error because the request is failing as cURL is unable to verify the certificate provided by the server.
You can solve the problem either way -
Allows curl command to work with “insecure” or “invalid” SSL certificates without https certificates. Use cURL with -k option which allows curl to make insecure connections, that is cURL does not verify the certificate.
Add the root CA (the CA signing the server certificate) to /etc/ssl/certs/ca-certificates.crt
Using Guzzle: Set verify to false
$client->request('GET', 'https://somewebsite.com', ['verify' => false]);
Note: It is best to install SSL certificate.
I am migrating my application from php 5 to php 7.2.
I have a problem with theSoapclient call knowing that it works correctly with php 5.
After a lot of research I am progressing on my soapClient script with php 7.2, but I have a concern for stability.
The script will load the wsdl a few times, like 1 time out of 40 and then indicate a loading problem.
[message:protected] => SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://ip?WSDL' : failed to load external entity "http://ip?WSDL"
I added the stream_context , cache_wsdl options but no stable result!
it worked twice with this code bellow
$option = array (
'location' => $optionSc['location'],
'uri' => $optionSc['location'],
'login' => $optionSc['login'],
'password' => $optionSc['password'],
'trace' => 1,
'connection_timeout' => 0,
'exceptions' => 1
);
after that it returns like I described first.
anyone can help me with that if he fixed this problem I did a lot of researches but nothing is working fine and I am relly blocked!
I've experienced a similar behaviour. PHP was reporting errors with parsing remote WSDL.
The problem was weak certificate used by the remote server that kept being refused by OpenSSL, even before being processed by PHP.
Problem
I have confirmed this by trying to download the WSDL using curl
curl REMOTE_ADDRESS
which reported the following error
error:14082174:SSL routines:SSL3_CHECK_CERT_AND_ALGORITHM:dh key too small.
The diffie-hellman key base was 1024 instead of recommended 2048 which I checked using openssl command (see https://weakdh.org/)
openssl s_client -showcerts -connect admonitoring.mediaresearch.cz:443 </dev/null
Solution
Until the certificate problem is fixed and a new one, more secure, issued, I have managed to fix this problem by temporarily lowering Openssl security settings.
In /etc/ssl/openssl.cnf (Debian) comment out the following line
# comment out the following line in /etc/ssl/openssl.cnf
CipherString = DEFAULT#SECLEVEL=2
# or set SECLEVEL to 1
CipherString = DEFAULT#SECLEVEL=1
Instead of changing the settings on the whole system, I solved it by using:
$options['ssl']['ciphers'] = 'DEFAULT#SECLEVEL=1';
in the stream_context
I am working on a project that is hosted on Google App Engine, and using app_devserver for local development. At the start I had problems with certificates but when I finally got over that error I am getting this new error
I am using Windows 10 and PHPstorm for development.
Error:
Message: cURL error 0: The cURL request was retried 3 times and did
not succeed. The most likely reason for the failure is that cURL was
unable to rewind the body of the request and subsequent retries
resulted in the same error. Turn on the debug option to see what went
wrong. See https://bugs.php.net/bug.php?id=47204 for more information.
(see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
Looks like this error is saying that the request is made and successfull but the body could not be resolved or parsed? How can I resolve it?
This is my PHP code if needed: (simple call to tag manager api v2)
$client = new Google_Client();
$client->setAuthConfig('service_account.json');
$client->setApplicationName("gtmdocx");
/*$client->setScopes(['https://www.googleapis.com/auth/tagmanager.readonly',
'https://www.googleapis.com/auth/tagmanager.manage.accounts',
'https://www.googleapis.com/auth/tagmanager.edit.containers']);*/
$client->setScopes(['https://www.googleapis.com/auth/tagmanager.readonly']);
$service = new Google_Service_TagManager($client);
$results = $service->accounts->listAccounts();
echo $_GET['callback'] . '('.json_encode($results).')';
I had exactly this problem using the Google Drive app, after hours trying to find a solution, I got it to work using the GuzzleHttp sink option
$client = new \Google_Client();
// ... Client Configuration
$httpClient = new Client([
'sink' => 'path_to_any_temp_file',
'base_uri' => $client->getConfig('base_path'),
]);
$client->setHttpClient($httpClient);
Worth the try.
I have one problem in ONE host: I cannot access an HTTP url (say, http://foo-bar.com:9999/Path/To/My/Soap.svc?wsdl).
Hitting such URL from my localhost (running PHP 5.4) works fine. However, hitting such url from my target server (running PHP 5.5) brings me this SoapFault:
Parsing WSDL: Couldn't load from 'http://foo-bar.com:9999/Path/To/My/Soap.svc?wsdl' : failed to load external entity "http://foo-bar.com:9999/Path/To/My/Soap.svc?wsdl"
(I did not disclose the URL due to contract policies)
What can I check? (Since the url is not in HTTPS but just HTTP, openssl should be discarded)
Code:
new SoapClient(
'http://foo-bar.com:9999/Path/To/My/Soap.svc?wsdl',
array('uri' => 'http://foo-bar.com/wsdl/schema/')
);
Found it: There's nothing wrong in the SOAP client between PHP versions. They remain compatible between -at least- 5.2 and 5.5. So there's nothing weird to test here, but just simple connection tests.
Issues like this should be tested with: file_get_contents('http://foo-bar.com:9999/Path/To/My/Soap.svc?wsdl') (modern PHP versions have fopen_wrappers active by default).
The answer? Connections are refused. That's why I get such error.
I am trying to connect to the google API from a localhost, but keep on receiving an exception (key changed - in text below).
Warning: file_get_contents(compress.zlib://https://www.googleapis.com/books/v1/volumes?q=Henry+David+Thoreau&filter=free-ebooks&key=bItatTTTTT7amAHYSaROTTTTTbtttuuuuuuuu) [function.file-get-contents]: failed to open stream: operation failed in C:\zendProject\zf2\vendor\google\apiclient\src\Google\IO\Stream.php on line 115
The code I am using in my browser comes straight from the API Guide and reads:
$client = new \Google_Client();
$client->setApplicationName("rent");
$service = new \Google_Service_Books($client);
$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
I think my problems relate to the config file, and that fact I am working off the localhost development server.
'Google_Auth_OAuth2' => array(
'application_name' => 'www.example.com',
'client_id' => '4498xxxxx061-3333xxxx9pjcpkbqhoxxxxxxxxxxx.apps.googleusercontent.com',
'client_secret' => '8xxxxxxxxx333xxxxxxxxx',
'redirect_uri' => 'http://localhost',
'developer_key' => 'AxxxxxxzBjpxxxxxaxxxxxxZxxx1xxxxx',
In the new developer console I have created a new client ID for the project and inserted the "Client_id", "Client_secret", etc.
I have also enabled the relevant APIs for Calenders and Books.
I have tested my API key on the URL I found for google fonts - so I am sure I have the right developer key.
I suspect the issue may be around the local host in uri fields, what do I need to put in here?
Does anyone know what I am doing wrong.
UPDATE: I found a post that suggested getting the HTTP response code here:
The response from the server is 304 - not sure if this helps
UPDATE: #Carlos Roubles - was correct I was using the incorrect version. Just in case anyone else runs into this issue - the composer information on the google website appears to be incorrect.
I previously used "google/apiclient": "1.0." this appears in the google documentation. I have now tried "google/apiclient": "1." and this seems to have fixed the problem.
Thats a problem with file_get_contents rather that with the api.
Most people changes file_get_contents to CURL for accesing remote files.
Anyways, i was checking the library and i cannot find any call to file_get_contents in all the stream.php file
https://github.com/google/google-api-php-client/blob/master/src/Google/IO/Stream.php
and in line 115, what we have is a commented line, so what comes to my mind is that yu are not using the last version of the library. Also, i see that in this version they make the request with fopen.
So you can try to update it, and probably this fixes the issue