Forums

API Error with free account

Hi,

I am trying to use this API: https://collectapi.com/api/economy/altin-doviz-ve-borsa-api?tab=pricing It is working well on my local computer. But I get an error on the console. Do you have any suggestions?

Traceback (most recent call last):
File "daily_test3.py", line 110, in <module>
RunCode()
File "daily_test3.py", line 31, in RunCode
    conn.request("GET", "/economy/exchange?int=10&to=TRY&base=USD", headers=headers)
File "/usr/lib/python3.8/http/client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1010, in _send_output
    self.send(msg)
File "/usr/lib/python3.8/http/client.py", line 950, in send
    self.connect()
File "/usr/lib/python3.8/http/client.py", line 1417, in connect
    super().connect()
File "/usr/lib/python3.8/http/client.py", line 921, in connect
    self.sock = self._create_connection(
File "/usr/lib/python3.8/socket.py", line 808, in create_connection
    raise err
File "/usr/lib/python3.8/socket.py", line 796, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network is unreachable

What is the domain you're using exactly? I see api.collectapi.com is already on our whitelist, so you should be able to connect to it with a free account.

Hi, thanks for the quick response. This is my code to access API;

conn = http.client.HTTPSConnection("api.collectapi.com")
headers = {
    'content-type': "application/json",
    'authorization': "**apikey**"
    }
conn.request("GET", "/economy/exchange?int=10&to=TRY&base=USD", headers=headers)
res = conn.getresponse()
data = res.read()

You may need to set the proxy details, see here.