adafruit / Adafruit_CircuitPython_Requests

Requests-like interface for web interfacing
MIT License
51 stars 36 forks source link

extra positionial arguments ?? #81

Closed jerryneedell closed 2 years ago

jerryneedell commented 2 years ago

I just updated a MAGTAG to the current tip of main and updated all the libraries to the current bundle. The code I am running has been running for several months but now it is failing when trying to get the localtime magtag.get_local_time()

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Connecting to AP Needell Airport
Getting time for timezone America/New_York
Traceback (most recent call last):
  File "code.py", line 92, in <module>
  File "adafruit_portalbase/__init__.py", line 411, in get_local_time
  File "adafruit_portalbase/network.py", line 231, in get_local_time
  File "adafruit_portalbase/network.py", line 200, in get_strftime
  File "adafruit_requests.py", line 615, in get
  File "adafruit_requests.py", line 556, in request
  File "adafruit_requests.py", line 428, in _get_socket
TypeError: extra positional arguments given

Code done running.

Press any key to enter the REPL. Use CTRL-D to reload.

Has something changed?

here is the code.py

# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
import sys
import time
import board
import digitalio
import neopixel
import ipaddress
import wifi
import socketpool
import time
import adafruit_requests
import ssl
import espidf
from adafruit_magtag.magtag import MagTag
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError

try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

SOLAREDGE_SOURCE = "https://monitoringapi.solaredge.com/site/"+secrets['solaredge_SiteID']+"/overview?format=json&api_key="+secrets['solaredge_apikey']
LAST_UPDATE_TIME = ['overview', 'lastUpdateTime']
LIFE_TIME_DATA =   ['overview', 'lifeTimeData',  'energy']
LAST_YEAR_DATA =   ['overview', 'lastYearData',  'energy']
LAST_MONTH_DATA =  ['overview', 'lastMonthData', 'energy']
LAST_DAY_DATA =    ['overview', 'lastDayData',   'energy']
CURRENT_POWER =    ['overview', 'currentPower',  'power']

try:
    magtag = MagTag(
        url=SOLAREDGE_SOURCE,
        json_path=(LAST_UPDATE_TIME, LIFE_TIME_DATA,
                   LAST_YEAR_DATA, LAST_MONTH_DATA,
                   LAST_DAY_DATA, CURRENT_POWER),
    )
except Exception as e:
    print("Some error occured -", e)
    magtag.exit_and_deep_sleep(60)

# Date stamp of info
magtag.add_text(
    text_font="/fonts/Arial-Bold-12.bdf",
    text_position=(10, 15),
    text_transform=lambda x: "Update Time: {}".format(x[0:10]),
)
# Lifetime
magtag.add_text(
    text_font="/fonts/Arial-Bold-12.bdf",
    text_position=(10, 35),
    text_transform=lambda x: "Lifetime Energy:   {:,}".format(x),
)
# YTD
magtag.add_text(
    text_font="/fonts/Arial-Bold-12.bdf",
    text_position=(10, 55),
    text_transform=lambda x: "Last Year Energy:   {:,}".format(x),
)
# Month
magtag.add_text(
    text_font="/fonts/Arial-Bold-12.bdf",
    text_position=(10, 75),
    text_transform=lambda x: "Last Month Energy:   {:,}".format(x),
)
# Day
magtag.add_text(
    text_font="/fonts/Arial-Bold-12.bdf",
    text_position=(10, 95),
    text_transform=lambda x: "Last Day Energy:   {:,}".format(x),
)
# Now
magtag.add_text(
    text_font="/fonts/Arial-Bold-12.bdf",
    text_position=(10, 115),
    text_transform=lambda x: "Current Power:   {:,}".format(x),
)

# updated time
magtag.add_text(
    text_font="/fonts/Arial-Bold-12.bdf",
    text_position=(245, 30),
    line_spacing=0.75,
    is_data=False
)

magtag.get_local_time()
try:
    now = time.localtime()
    print("Now: ", now)

    # display the current time since its the last-update
    updated_at = "%d/%d\n%d:%02d" % now[1:5]
    magtag.set_text(updated_at, 6, False)

    # get data from the JSON QUERY
    value = magtag.fetch()
    print("Response is", value)

    print("Solar_now: {0}".format(value[5]))
    print("Solar_day: {0}".format(value[4]))
    print("Solar_month: {0}".format(value[3]))
    print("Solar_YTD: {0}".format(value[2]))
    print("Sending to Adafruit IO...")
    magtag.push_to_io("magtag-solar-day", value[4])
    magtag.push_to_io("magtag-solar-month", value[3])
    magtag.push_to_io("magtag-solar-ytd", value[2])
    magtag.push_to_io("magtag-solar-now", value[5])

except (ValueError, RuntimeError) as e:
    print("Some error occured -", e)
    magtag.exit_and_deep_sleep(60)

time.sleep(2) # let screen finish updating
#magtag.peripherals.neopixel_disable = True # turn off lights

# update hourly from 7AM to 6PM
next_hour = 7
if (now[3] > 7) and (now[3] < 18):
    next_hour = now[3] + 1

event_time = time.struct_time((now[0], now[1], now[2],
                               next_hour, 0, 0,
                               -1, -1, now[8]))
#print("event_time :", event_time)

# how long is that from now?
remaining = time.mktime(event_time) - time.mktime(now)
if remaining < 0:             # ah its aready happened today...
    remaining += 24 * 60 * 60 # wrap around to the next day
remaining_hrs = remaining // 3660
remaining_min = (remaining % 3600) // 60
print("Gonna zzz for %d hours, %d minutes" % (remaining_hrs, remaining_min))

# Turn it all off and go to bed till the next update time
magtag.exit_and_deep_sleep(remaining)
Neradoc commented 2 years ago

I reproduced the issue with the following code, and from my tests it seems the issue appears with this Circuitpython PR: https://github.com/adafruit/circuitpython/pull/5439

import socketpool
import ssl
import wifi
import adafruit_requests
from secrets import secrets
wifi.radio.connect(ssid=secrets["ssid"], password=secrets["password"])
socket_pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(socket_pool, ssl.create_default_context())
response = requests.get("http://wifitest.adafruit.com/testwifi/index.html")
print(response.text)
jerryneedell commented 2 years ago

@Neradoc Thank you!

jerryneedell commented 2 years ago

FYI - my code does run normally with the 7.0.0 release.

jerryneedell commented 2 years ago

fixed by #82