Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Problem with PyPortal.fetch
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Problem with PyPortal.fetch

by viennamike on Fri Oct 16, 2020 12:42 am

I'm trying to get data from Virginia's COVID data sets, which use the Socrata API and returns json. It works on my PC, using requests. The URL is
Code: Select all | TOGGLE FULL SIZE
''https://data.virginia.gov/resource/bre9-aqqr.json?$query= SELECT report_date, sum(total_cases) WHERE report_date between "2020-10-09T00:00:00.000" and "2020-10-16T00:00:00.000" AND vdh_health_district IN ("Alexandria", "Fairfax", "Arlington", "Loudoun", "Prince William") GROUP BY report_date''


On my PC, r.text shows
Code: Select all | TOGGLE FULL SIZE
[{"report_date":"2020-10-09T00:00:00.000","sum_total_cases":"52840"}
,{"report_date":"2020-10-10T00:00:00.000","sum_total_cases":"53121"}
,{"report_date":"2020-10-11T00:00:00.000","sum_total_cases":"53318"}
,{"report_date":"2020-10-12T00:00:00.000","sum_total_cases":"53592"}
,{"report_date":"2020-10-13T00:00:00.000","sum_total_cases":"53886"}
,{"report_date":"2020-10-14T00:00:00.000","sum_total_cases":"54040"}
,{"report_date":"2020-10-15T00:00:00.000","sum_total_cases":"54354"}]


and it parses fine using r.json(). However, when I try using PyPortal.fetch for the same URL string on the PyPortal, I get back an error on that line, with the message
"nva_counts = PyPortal.fetch(nva_count_URL)"

Any clues as to what's going wrong?
p.s.: I'm running CircuitPython 5.3.1

viennamike
 
Posts: 16
Joined: Tue Feb 12, 2013 6:49 pm

Re: Problem with PyPortal.fetch

by dastels on Fri Oct 16, 2020 12:49 pm

I think that's the line that's causing the error. What gets printed in the REPL?

Dave

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

Re: Problem with PyPortal.fetch

by viennamike on Fri Oct 16, 2020 1:46 pm

dastels wrote:I think that's the line that's causing the error. What gets printed in the REPL?
Dave

Sorry, I pasted the wrong thing above. I meant to post the REPL message, which is:
Traceback (most recent call last):
File "code.py", line 221, in <module>
File "adafruit_pyportal.py", line 787, in fetch
AttributeError: 'str' object has no attribute '_debug'

I get the same error with a simpler request which sends back the complete set of data, using a URL of https://data.virginia.gov/resource/bre9-aqqr.json

viennamike
 
Posts: 16
Joined: Tue Feb 12, 2013 6:49 pm

Re: Problem with PyPortal.fetch

by viennamike on Fri Oct 16, 2020 2:23 pm

Nevermind, and my thanks to the folks over on the Discord channel. I had mistakenly typed in PyPortal.fetch rather than using the PyPortal instance I had previously created. That's what I get for trying to port code over from Windows using requests at 1 am.

viennamike
 
Posts: 16
Joined: Tue Feb 12, 2013 6:49 pm

Re: Problem with PyPortal.fetch

by dastels on Fri Oct 16, 2020 3:15 pm

:) It happens.

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

Please be positive and constructive with your questions and comments.