CoCalc Public FilesPublic / PYTHON / 00-ping.ipynbOpen with one click!
Author: Hal Snyder
Views : 171
Description: Ping the CoCalc API
Compute Environment: Ubuntu 18.04 (Deprecated)

API Examples 00-ping

This example will check whether you can reach the CoCalc API service.

Security key is not required for ping. You can pass empty strings for user and password in the HTTP POST authentication.

In [1]:
import requests from requests.auth import HTTPBasicAuth import json import pprint
In [2]:
pp = pprint.PrettyPrinter()
In [3]:
s = requests.Session() a = requests.adapters.HTTPAdapter(max_retries=3) s.mount('https://', a) url = "https://cocalc.com/api/v1/ping" auth = HTTPBasicAuth('','') headers = {'content-type': 'application/json'} r = s.post(url,auth=auth,headers=headers) assert r.status_code == requests.codes.ok,"bad status code {}".format(r.status_code) pp.pprint(r.json())
{'event': 'pong', 'id': 'ec94a824-46a4-48b5-808a-51946251bb8a', 'now': '2017-11-16T15:45:52.428Z'}
In [ ]: