Hello, I have simple code that doesn’t work in python. Confused as to what I am doing wrong.
conn = http.client.HTTPSConnection("api.coinbase.com")
payload = ''
headers = {
'Content-Type': 'application/json'
}
conn.request("GET", "/api/v3/brokerage/products/BTC-USD/candles?start=20333003&end=20333003&granularity=ONE_DAY", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Here is the response
python3 btc_graph_coinbase.py
Traceback (most recent call last):
File “/Users/patjatin/workspace/VisualStudioCodeProjects/StockBot/btc_graph_coinbase.py”, line 118, in
get_hist_btc1()
File “/Users/patjatin/workspace/VisualStudioCodeProjects/StockBot/btc_graph_coinbase.py”, line 23, in get_hist_btc1
conn.request(“GET”, “/api/v2/brokerage/products/BTC-USD/candles?start=20333003&end=20333003&granularity=ONE_DAY”, payload, headers)
File “/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py”, line 1286, in request
self._send_request(method, url, body, headers, encode_chunked)
File “/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py”, line 1332, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File “/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py”, line 1281, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File “/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py”, line 1041, in _send_output
self.send(msg)
File “/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py”, line 979, in send
self.connect()
File “/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py”, line 1451, in connect
super().connect()
File “/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py”, line 945, in connect
self.sock = self._create_connection(
^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/socket.py”, line 827, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/socket.py”, line 962, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno 8] nodename nor servname provided, or not known