I am trying to save response from an HTTP request in a global variable using globals() in python so that I can use that data later.
def request_agent(agent_name, urL):
r = requests.get(urL)
data = r.json()
globals()[agent_name] = data
But when I write my test case to verify if that value has been saved or not, I get an error saying that the variable is not defined. Below is my test case.
class TinyTest(unittest.TestCase):
def test_request_agent(self):
agent_name = 'location'
url = 'http://free.ipwhois.io/json/'
tt.request_agent(agent_name, url)
self.assertEqual(eval(location['continent']), 'Europe')
What am I doing wrong here?