我试图通过循环传递多个IP地址来收集来自API的响应。
import urllib2
z = open("ipaddr.txt","r")
for i in z:
apr = urllib2.Request('https://someurl;ip='+i+';req=profile')
f = urllib2.urlopen(apr)
the_page = f.read()
print the_page
通过运行上述代码会出现以下错误
Traceback (most recent call last):
File "open.py", line 10, in <module>
f = urllib2.urlopen(apr)
File "/usr/lib64/python2.6/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib64/python2.6/urllib2.py", line 389, in open
req = meth(req)
File "/usr/lib64/python2.6/urllib2.py", line 1096, in do_request_
raise URLError('no host given')