🎁📬❄️📦 Holiday Shipping Deadlines are approaching! International customers and domestic ground - get your orders in 12/9/2020 📦❄️📬🎁
0

CircuitPython/Matrix Portal m4 -Failed to request hostname
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

CircuitPython/Matrix Portal m4 -Failed to request hostname

by belsonc on Sun Nov 15, 2020 6:44 pm

Hi -

I'm trying to connect to a website to pull down a json file, and I'm following pieces of code I've found online. However, the code is giving me the above error (full REPL output below). Relevant section of my code:
Code: Select all | TOGGLE FULL SIZE
import time
import adafruit_display_text.label
import json
import adafruit_requests as requests
import board
from adafruit_matrixportal.matrixportal import MatrixPortal
from adafruit_matrixportal.network import Network

matrixportal = MatrixPortal(status_neopixel=board.NEOPIXEL, debug=False)

from secrets import secrets
json_Source = 'http://static.nfl.com/liveupdate/scores/scores.json'
json_Data = requests.get(json_Source)


And the output from REPL:
Code: Select all | TOGGLE FULL SIZE
code.py output:
Set background to  0
Traceback (most recent call last):
  File "code.py", line 14, in <module>
  File "adafruit_requests.py", line 674, in get
  File "adafruit_requests.py", line 572, in request
  File "adafruit_requests.py", line 432, in _get_socket
  File "adafruit_esp32spi/adafruit_esp32spi_socket.py", line 42, in getaddrinfo
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 604, in get_host_by_name
RuntimeError: Failed to request hostname


I've replaced the two py files referenced above to no avail - any thoughts? Thanks in advance. (For what it's worth, I've made another project where I would connect to Adafruit IO, and that worked without issue, so I know I can connect to the web.)

belsonc
 
Posts: 25
Joined: Tue Sep 15, 2020 8:39 pm

Re: CircuitPython/Matrix Portal m4 -Failed to request hostna

by dastels on Sun Nov 15, 2020 8:22 pm

You're not connecting to the network. You can make use of the MatrixPortal object you';re creating to take care of the details: Replace:
Code: Select all | TOGGLE FULL SIZE
json_Data = requests.get(json_Source)

with:
Code: Select all | TOGGLE FULL SIZE
json_Data = matrixportal.fetch(json_Source)


Assuming your secrets file is correct, it should work. I just made that change and am getting data back:
Code: Select all | TOGGLE FULL SIZE
code.py output:
Set background to  0
Connecting to AP Shibari
Retrieving data...Socket missing recv_into. Using more memory to be compatible
Reply is OK!
{"2020111506":{"home":{"score":{"1":3,"2":0,"3":0,"4":0,"5":0,"T":3},"abbr":"ARI","to":3},"away":{"score":{"1":7,"2":3,"3":0,"4":0,"5":0,"T":
10},"abbr":"BUF","to":3},"bp":2,"down":2,"togo":20,"clock":"12:51","posteam":"ARI","note":null,"redzone":false,"stadium":"State Farm Stadium"
,"media":{"radio":{"home":null,"away":null},"tv":"CBS","sat":null,"sathd":null},"yl":"ARI 43","qtr":"2"},"2020111507":{"home":{"score":{"1":7
,"2":0,"3":0,"4":0,"5":0,"T":7},"abbr":"LV","to":3},"away":{"score":{"1":3,"2":0,"3":0,"4":0,"5":0,"T":3},"abbr":"DEN","to":3},"bp":2,"down":
3,"togo":7,"clock":"00:40","posteam":"LV","note":null,"redzone":false,"stadium":"Allegiant Stadium","media":{"radio":{"home":null,"away":null
},"tv":"CBS","sat":null,"sathd":null},"yl":"DEN 36","qtr":"1"},"2020111512":{"home":{"score":{"1":14,"2":0,"3":0,"4":0,"5":0,"T":14},"abbr":"
MIA","to":3},"away":{"score":{"1":0,"2":0,"3":0,"4":0,"5":0,"T":0},"abbr":"LAC","to":3},"bp":2,"down":3,"togo":10,"clock":"14:02","posteam":"
MIA","note":null,"redzone":false,"stadium":"Hard Rock Stadium","media":{"radio":{"home":null,"away":null},"tv":"CBS","sat":null,"sathd":null}
,"yl":"MSIA 44","qtr":"2"},"2020111505":{"home":{"score":{"1":3,"2":0,"3":0,"4":0,"5":0,"T":3},"abbr":"PIT","to":3},"away":{"score":{"1":0,"2"
:0,"3":0,"4":0,"5":0,"T":0},"abbr":"CIN","to":3},"bp":1,"down":1,"togo":20,"clock":"10:18","posteam":"PIT","note":null,"redzone":false,"stadi
um":"Heinz Field","media":{"radio":{"home":null,"away":null},"tv":"FOX","sat":null,"sathd":null},"yl":"PIT 24","qtr":"1"},"2020111509":{"home
":{"score":{"1":3,"2":0,"3":0,"4":0,"5":0,"T":3},"abbr":"LA","to":3},"away":{"score":{"1":7,"2":0,"3":0,"4":0,"5":0,"T":7},"abbr":"SEA","to":
3},"bp":1,"down":3,"togo":4,"clock":"05:14","posteam":"LA","note":null,"redzone":false,"stadium":"SoFi Stadium","media":{"radio":{"home":null
,"away":null},"tv":"FOX","sat":null,"sathd":null},"yl":"LA 29","qtr":"1"},"2020111510":{"home":{"score":{"1":0,"2":0,"3":0,"4":0,"5":0,"T":0}
,"abbr":"NO","to":3},"away":{"score":{"1":7,"2":0,"3":0,"4":0,"5":0,"T":7},"abbr":"SF","to":3},"bp":1,"down":3,"togo":18,"clock":"05:36","pos
team":"SF","note":null,"redzone":false,"stadium":"Mercedes-Benz Superdome","media":{"radio":{"home":null,"away":null},"tv":"FOX","sat":null,"
sathd":null},"yl":"SF 17","qtr":"1"},"2020111511":{"home":{"score":{"1":0,"2":0,"3":0,"4":0,"5":0,"T":0},"abbr":"NE","to":3},"away":{"score":
{"1":0,"2":0,"3":0,"4":0,"5":0,"T":0},"abbr":"BAL","to":3},"bp":0,"down":0,"togo":0,"clock":"15:00","posteam":"BAL","note":null,"redzone":fal
se,"stadium":"Gillette Stadium","media":{"radio":{"home":null,"away":null},"tv":"NBC","sat":null,"sathd":null},"yl":"","qtr":"Pregame"},"2020
111500":{"home":{"score":{"1":14,"2":3,"3":0,"4":6,"5":0,"T":23},"abbr":"CAR","to":0},"away":{"score":{"1":7,"2":10,"3":12,"4":17,"5":0,"T":4
6},"abbr":"TB","to":2},"bp":19,"down":0,"togo":0,"clock":"00:38","posteam":"TB","note":null,"redzone":false,"stadium":"Bank of America Stadiu
m","media":{"radio":{"home":null,"away":null},"tv":"FOX","sat":null,"sathd":null},"yl":"","qtr":"Final"},"2020111501":{"home":{"score":{"1":3
,"2":0,"3":0,"4":7,"5":0,"T":10},"abbr":"CLE","to":2},"away":{"score":{"1":0,"2":0,"3":0,"4":7,"5":0,"T":7},"abbr":"HOU","to":0},"bp":13,"dow
n":0,"togo":0,"clock":"00:31","posteam":"CLE","note":null,"redzone":false,"stadium":"FirstEnergy Stadium","media":{"radio":{"home":null,"away
":null},"tv":"FOX","sat":null,"sathd":null},"yl":"","qtr":"Final"},"2020111502":{"home":{"score":{"1":7,"2":10,"3":7,"4":6,"5":0,"T":30},"abb
r":"DET","to":1},"away":{"score":{"1":3,"2":0,"3":7,"4":17,"5":0,"T":27},"abbr":"WAS","to":0},"bp":12,"down":0,"togo":0,"clock":"00:00","post
eam":"DET","note":null,"redzone":false,"stadium":"Ford Field","media":{"radio":{"home":null,"away":null},"tv":"FOX","sat":null,"sathd":null},
"yl":"","qtr":"Final"},"2020111503":{"home":{"score":{"1":0,"2":17,"3":0,"4":7,"5":0,"T":24},"abbr":"GB","to":1},"away":{"score":{"1":3,"2":7
,"3":7,"4":3,"5":0,"T":20},"abbr":"JAC","to":0},"bp":16,"down":0,"togo":0,"clock":"00:32","posteam":"GB","note":null,"redzone":false,"stadium
":"Lambeau Field","media":{"radio":{"home":null,"away":null},"tv":"FOX","sat":null,"sathd":null},"yl":"","qtr":"Final"},"2020111504":{"home":
{"score":{"1":7,"2":7,"3":7,"4":6,"5":0,"T":27},"abbr":"NYG","to":3},"away":{"score":{"1":3,"2":0,"3":14,"4":0,"5":0,"T":17},"abbr":"PHI","to
":0},"bp":10,"down":0,"togo":0,"clock":"00:22","posteam":"NYG","note":null,"redzone":false,"stadium":"MetLife Stadium","media":{"radio":{"hom
e":null,"away":null},"tv":"FOX","sat":null,"sathd":null},"yl":"","qtr":"Final"},"2020111600":{"home":{"score":{"1":null,"2":null,"3":null,"4"
:null,"5":null,"T":null},"abbr":"CHI","to":null},"away":{"score":{"1":null,"2":null,"3":null,"4":null,"5":null,"T":null},"abbr":"MIN","to":nu
ll},"bp":0,"down":null,"togo":null,"clock":null,"posteam":null,"note":null,"redzone":null,"stadium":"Soldier Field","media":{"radio":{"home":
null,"away":null},"tv":"ESPN","sat":null,"sathd":null},"yl":null,"qtr":null},"2020111200":{"home":{"score":{"1":7,"2":10,"3":0,"4":0,"5":0,"T
":17},"abbr":"TEN","to":3},"away":{"score":{"1":3,"2":10,"3":14,"4":7,"5":0,"T":34},"abbr":"IND","to":2},"bp":16,"down":0,"togo":0,"clock":"0
0:41","posteam":"TEN","note":null,"redzone":false,"stadium":"Nissan Stadium","media":{"radio":{"home":null,"away":null},"tv":"FOX","sat":null
,"sathd":null},"yl":"","qtr":"Final"}}

dastels
 
Posts: 4251
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.