I have a python code that reads from a URL.
def submitTest(self,url):
response = None
if url is not None:
wptUrl = WebPageTestConfigUtils.getConfigValue('runTestURL')+"?f=json&url="+url+"&runs=3&video=1&web10=0&fvonly=1&mv=1&private=1&location=us_east_wptdriver:Chrome.DSL"
with closing(urllib.urlopen(wptUrl)) as response:
json.load(response)
return response["data"]["testId"]
I used the context lib docs https://docs.python.org/2/library/contextlib.html to close the python connection. But then I get the following error on executing.
Traceback (most recent call last):
File "webPageTestUtils.py", line 59, in <module>
main()
File "webPageTestUtils.py", line 56, in main
print webPageTestProcessor.submitTest("www.amazon.com")
File "webPageTestUtils.py", line 27, in submitTest
return response["data"]["testId"]
AttributeError: addinfourl instance has no attribute '__getitem__'
What I am doing wrong here . I need a way to close the connection if something bad happens or if I am done with it.