top of page

1.19.23

  • owenmichael12333
  • Jan 19, 2023
  • 2 min read

I continued working on my OLED display and, while I no longer have the same ImportError, it has been replaced by a different on.

Traceback (most recent call last):
  File "code.py", line 7, in <module>
ImportError: no module named 'ssl'

Mr. Christy helped me and showed me some code to use however I keep receiving this error despite using, to my knowledge, the correct code. I am currently trying to reinstall libraries and hope that that will help fix the issue.

import time
import os
import ssl
import wifi
import socketpool
import microcontroller
import adafruit_requests

wifi.radio.connect(
    os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD")
)

# Use cityname, country code where countrycode is ISO3166 format.
# E.g. "New York, US" or "London, GB"
location = "Manhattan, US"

# openweathermap URL, brings in your location & your token
url = "http://api.openweathermap.org/data/2.5/weather?q=" + location
url += "&appid=" + os.getenv("openweather_token")

pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())

while True:
    try:
        #  pings openweather
        response = requests.get(url)
        #  packs the response into a JSON
        response_as_json = response.json()
        print()
        #  prints the entire JSON
        print(response_as_json)
        #  gets location name
        place = response_as_json["name"]
        #  gets weather type (clouds, sun, etc)
        weather = response_as_json["weather"][0]["main"]
        #  gets humidity %
        humidity = response_as_json["main"]["humidity"]
        #  gets air pressure in hPa
        pressure = response_as_json["main"]["pressure"]
        #  gets temp in kelvin
        temperature = response_as_json["main"]["temp"]
        #  converts temp from kelvin to F
        converted_temp = (temperature - 273.15) * 9 / 5 + 32
        #  converts temp from kelvin to C
        #  converted_temp = temperature - 273.15

        #  prints out weather data formatted nicely as pulled from JSON
        print()
        print("The current weather in %s is:" % place)
        print(weather)
        print("%s°F" % converted_temp)
        print("%s%% Humidity" % humidity)
        print("%s hPa" % pressure)
        #  delay for 5 minutes
        time.sleep(300)
    # pylint: disable=broad-except
    except Exception as e:
        print("Error:\n", str(e))
        print("Resetting microcontroller in 10 seconds")
        time.sleep(10)
        microcontroller.reset()

 
 
 

Recent Posts

See All
5.11.23

This week I did not get much done due to very few class periods this week. I spent the beginning of the week working on cleaning up the...

 
 
 

Comments


bottom of page