URL에서 읽는 python 코드가 있습니다.python에서 urllib.urlopen 연결을 닫는 방법
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"]
나는 문맥 lib 문서 https://docs.python.org/2/library/contextlib.html을 사용하여 파이썬 연결을 닫습니다. 하지만 다음 실행에 다음과 같은 오류가 발생합니다.
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__'
내가 여기서 잘못하고있는 것. 나쁜 일이 생기거나 내가 그 일을 끝내면 연결을 닫을 방법이 필요합니다.
가능한 중복 끝나면 연결을 닫습니다이 방법 (HTTP [내가 urllib.urlopen 후 close()를 호출해야합니다()를?] : // 유래. co.kr/questions/1522 –