HTTPGet with headers and parameters
-
My apologies first, I'm not a programmer by trade, I can hack together and follow examples along pretty well, but sometimes I get stumped. Does the urequest library not have the means to pass the parameters for the query like below. I need to pass the header information for the API key and then I need to pass the parameters, the stock symbol and the type of quote I am looking for. Below is the snippet of code from RapidAPI. I was trying to get this to work in UIFlow and I've gotten most of it, but I'm stumped on how to pass the query parameters. Maybe there's an easier way all together. Just wanted to do a simple stock ticker. At the moment, it returns a message :This API function () does not exist
Snippet from Rapidapi:
import requestsurl = "https://alpha-vantage.p.rapidapi.com/query"
querystring = {"symbol":"TSLA","function":"GLOBAL_QUOTE"}headers = {
'x-rapidapi-host': "alpha-vantage.p.rapidapi.com",
'x-rapidapi-key': "XXXXXXXX"
}
response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)Snippet from UIflow:
from m5stack import *
from m5ui import *
from uiflow import *
import urequests
import timesetScreenColor(0x222222)
while True:
try:
req = urequests.request(method='GET', url='https://alpha-vantage.p.rapidapi.com/query', headers={'x-rapidapi-host':'alpha-vantage.p.rapidapi.com','x-rapidapi-key':'xxxxx'})
lcd.print('success', 0, 0, 0xffffff)
lcd.print((req.text), 0, 0, 0xffffff)
except:
lcd.print('CRAPPED OUT', 0, 0, 0xffffff)
wait(60)