2

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);
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • What does your curl command look like exactly? – Gabriel Littman Jun 09 '17 at 21:21
  • Possible duplicate of https://stackoverflow.com/questions/26148701/file-get-contents-ssl-operation-failed-with-code-1-and-more – manassehkatz-Moving 2 Codidact Jun 09 '17 at 21:32
  • is the URL you are trying to reach an HTTPS address (as your results with the online emulator seem to suggest)? if so, what are you doing to pass the required credentials? – FKEinternet Jun 09 '17 at 21:37
  • Possibly link to redirection. YOu can find answer [here](https://stackoverflow.com/questions/4323985/how-to-get-the-real-url-after-file-get-contents-if-redirection-happens) – Kaenn Jun 09 '17 at 21:44
  • yeah its an http address which requires a username and apikey, but thats included in the address – HollyPocket27 Jun 09 '17 at 21:53
  • Also, I don't believe its redirected cause the url in the browser once the page is loaded is the same as what the code has... unless you can redirect without it showing in the address bar, which sounds hella sketch – HollyPocket27 Jun 09 '17 at 21:55
  • Would be nice to see your actual Python code – pstatix Jun 10 '17 at 00:13

0 Answers0