0

wget didn't write a complete file
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

wget didn't write a complete file

by slowjim on Thu Feb 13, 2020 9:27 pm

Hi,

I am trying to get my PyPortal Titano set up with the NASA Apod. I have come across a few hitches along the way which I have overcome, but I am now stuck. When the code loads up I get the following REPL feedback:

code.py output:
Set background to /pyportal_startup.bmp
ESP firmware: bytearray(b'1.2.2\x00')
Connecting to AP XXXXXXXXXX
Set background to /nasa_background.bmp
Retrieving data...Reply is OK!
original URL: https://apod.nasa.gov/apod/image/2002/t ... rR1024.jpg
convert URL: https://io.adafruit.com/api/v2/slowjim/ ... rR1024.jpg
Fetching stream from https://io.adafruit.com/api/v2/slowjim/ ... rR1024.jpg
Didn't receive full response, failing out
Some error occured, retrying! - wget didn't write a complete file
Retrieving data...Reply is OK!
original URL: https://apod.nasa.gov/apod/image/2002/t ... rR1024.jpg
convert URL: https://io.adafruit.com/api/v2/slowjim/ ... rR1024.jpg
Fetching stream from https://io.adafruit.com/api/v2/slowjim/ ... rR1024.jpg
Traceback (most recent call last):
File "code.py", line 37, in <module>
File "code.py", line 34, in <module>
File "adafruit_pyportal.py", line 913, in fetch
File "adafruit_pyportal.py", line 910, in fetch
File "adafruit_pyportal.py", line 896, in fetch
File "adafruit_pyportal.py", line 890, in fetch
File "adafruit_pyportal.py", line 666, in wget
KeyError: content-length

So it looks like it successfully connects to the wifi, identifies the web page but then comes throws an error: Didn't receive full response, failing out, Some error occured, retrying! - wget didn't write a complete file. It tries again and then throws the final error.

I have put a copy of my code below (note the only things I have changes are I added some libraries as per advice and I changed the sleep at the bottom to 10 seconds so I could see what was happening in the code) :

Code: Select all | TOGGLE FULL SIZE
import time
import board
from adafruit_pyportal import PyPortal
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests

# Set up where we'll be fetching data from
DATA_SOURCE = "https://api.nasa.gov/planetary/apod?api_key=TEFHvH0LHbXXXXXXXX6gypz98lxasavBz6HUhe"
# There's a few different places we look for data in the photo of the day
IMAGE_LOCATION = ["url"]
TITLE_LOCATION = ["title"]
DATE_LOCATION = ["date"]

# the current working directory (where this file is)
cwd = ("/"+__file__).rsplit('/', 1)[0]
pyportal = PyPortal(url=DATA_SOURCE,
                    json_path=(TITLE_LOCATION, DATE_LOCATION),
                    status_neopixel=board.NEOPIXEL,
                    default_bg=cwd+"/nasa_background.bmp",
                    text_font=cwd+"/fonts/Arial-12.bdf",
                    text_position=((5, 220), (5, 200)),
                    text_color=(0xFFFFFF, 0xFFFFFF),
                    text_maxlen=(50, 50), # cut off characters
                    image_json_path=IMAGE_LOCATION,
                    image_resize=(320, 240),
                    image_position=(0, 0))

while True:
    response = None
    try:
        response = pyportal.fetch()
        print("Response is", response)
    except RuntimeError as e:
        print("Some error occured, retrying! -", e)

    time.sleep(10)  # 30 minutes till next check

slowjim
 
Posts: 18
Joined: Fri Sep 27, 2019 3:49 am

Please be positive and constructive with your questions and comments.