What I’m trying to do:
Hi,
I am trying to get the results of my API when the button is clicked. But each time I try the terminal shows an error " NameError: name 'headers' is not defined
". I’ve tried testing my code on visual studio and it works perfectly but not for anvil.
Code Sample:
from anvil import *
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables
import anvil.http
import json
class Form1(Form1Template): #anvil.http.request
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Any code you write here will run when the form opens.
def button_1_click(self, **event_args):
url = "https://breachdirectory.p.rapidapi.com/"
querystring = {"func":"auto","term":self.UserData}
response = anvil.http.request(url, method="GET", headers=headers, params=querystring)
data = str(json.loads(response.text)) #12 char position
p = data[12]
if p == 'T':
self.output = "Your Data Has Been Leaked!"
else:
self.output = "Your Data Has Not Been Leaked"
"""This method is called when the button is clicked"""
pass
Clone link:
Anvil | Login