I am trying to get a JSON object from a URL. I have tried using PHP (both file_get_contents
and curl) and Python (both using urllib2
and requests
).
All error, but if I go to the URL with a browser it shows the JSON object. This is for my app on Apache2.
Here are the errors Im getting per command:
- file_get_contents --- failed to open stream
- cURL --- error 28: Connection timed out after 10001 milliseconds
Python request --
File "test.py", line 4, in <module> response= requests.get(url, timeout=2) File "/usr/lib/python2.7/dist-packages/requests/api.py", line 55, in get return request('get', url, * *kwargs) File "/usr/lib/python2.7/dist-packages/requests/api.py", line 44, in request return session.request(method=method, url=url, *kwargs) File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 455, in request resp = self.send(prep, * *send_kwargs) File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 558, in send r = adapter.send(request, * *kwargs) File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 387, in send raise Timeout(e) requests.exceptions.Timeout: (<urllib3.connectionpool.VerifiedHTTPSConnection instance at 0x7fbb3ec6d440>, 'Connection to **url** timed out. (connect timeout=2)')
I also tried running file_get_contents using a php online emulator just incase it was something with my server but I got this error
E_WARNING : type 2 -- file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed -- at line 4
E_WARNING : type 2 -- file_get_contents(): Failed to enable crypto -- at line 4
The curl code is:
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
if ( $result==false ) {
echo curl_errno($ch).' '.curl_error($ch);
}
curl_close($ch);