Forums

"OSError: [Errno 101] Network is unreachable" While using CollectAPI

I am building a python script that will run everyday using PythonAnywhere Tasks and I am running this a problem. This is my code.

 import smtplib
 import datetime
 import http.client
 import json

def wa_gas():
       token = "token"
       conn = http.client.HTTPSConnection("api.collectapi.com")

       headers = {
                'content-type': "application/json",
                 'authorization': token
         }

         conn.request("GET", "/gasPrice/stateUsaPrice?state=WA", headers=headers)

          res = conn.getresponse()
          data = res.read()

           d = data.decode("utf-8")
           d2 = json.loads(data)

           d3 = d2["result"]["cities"][10]["gasoline"]
           return f"Vancouver Average Regular:\n    ${str(d3)[:-1]}"

And I get getting this error message:

OSError: [Errno 101] Network is unreachable

I have checked the whitelist and CollectAPI is on there.

You need to configure the library that you're using to use the proxy. See the documentation of the library for how to do that and the details you need are here: https://help.pythonanywhere.com/pages/403ForbiddenError/