Getting 'NoneType' error when trying to pull data from MTA NYC API

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
dcliang
 
Posts: 6
Joined: Sun Jan 15, 2023 10:56 am

Getting 'NoneType' error when trying to pull data from MTA NYC API

Post by dcliang »

Hello, I'm encountering the below error in my REPL for the attached code.

File "code.py", line 19, in <module>
File "adafruit_requests.py", line 802, in request
AttributeError: 'NoneType' object has no attribute 'request'

What might some reasons be for this 'NoneType' error and how do I fix it? Is it because I'm requesting data from the NYC MTA API incorrectly and it is returning a null value or is it something else? I've been searching online for examples of how others may have accessed NYC MTA API data via CircuitPython but keep coming up short. Thanks in advance for the help.

For reference, I'm running CircuitPython 7.3.3 on a Matrix Portal.
Attachments
Code.JPG
Code.JPG (72.84 KiB) Viewed 40 times

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Getting 'NoneType' error when trying to pull data from MTA NYC API

Post by mikeysklar »

If you print the value of 'url' and try to manually pull it from the command line or go there in a browser are you able to get a response?

User avatar
dcliang
 
Posts: 6
Joined: Sun Jan 15, 2023 10:56 am

Re: Getting 'NoneType' error when trying to pull data from MTA NYC API

Post by dcliang »

Thanks for responding, mikeysklar.

Instead of trying to get the data directly from MTA NYC, I've now switched to getting the data from another website that already has the information converted to JSON. Referencing some code that I found online, I'm now using Network instead of request which works.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Getting 'NoneType' error when trying to pull data from MTA NYC API

Post by mikeysklar »

What source are you using for JSON formatted NYC MTA data?

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”