I am trying to use the Strava API v3 in Python, and I am afraid I am missing something. The docs say:
This base URL is used for all Strava API requests: https://api.strava.com
$ curl -i https://api.strava.com
HTTP/1.1 200 OK Content-Type: application/json Status: 200 OK X-RateLimit-Limit: 5000 X-RateLimit-Remaining: 4999 Content-Length: 2
Responses are in JSON format and gzipped.
I am currently doing this:
import urllib
print urllib.urlopen('https://api.strava.com').read()
And gettin this:
Traceback (most recent call last):
File "StravaAPIv3.py", line 3, in <module>
print urllib.urlopen('https://api.strava.com').read()
File "C:\Python27\lib\urllib.py", line 86, in urlopen
return opener.open(url)
File "C:\Python27\lib\urllib.py", line 207, in open
return getattr(self, name)(url)
File "C:\Python27\lib\urllib.py", line 436, in open_https
h.endheaders(data)
File "C:\Python27\lib\httplib.py", line 954, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 814, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 776, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 1157, in connect
self.timeout, self.source_address)
File "C:\Python27\lib\socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
IOError: [Errno socket error] [Errno 11004] getaddrinfo failed
I don't know where to start, since I don't know much about HTTP requests and HTTPS
UPDATE: According to Merlin's suggestion to use requests
module, I am doing this:
import requests
r = requests.get('https://api.strava.com/')
print r.status_code
print r.headers['content-type']
print r.encoding
print r.text
print r.json()
but keep getting an error:
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.strava.com', port=443): Max retries exceeded with url: / (Caused by <class 'so cket.gaierror'>: [Errno 11004] getaddrinfo failed)