当我在代理之外执行程序时,会运行以下代码。当我使用Windows 7操作系统在我的工作代理上运行此程序时,我使用Cygwin获取带有命令提示符的“[Errno 11004]”或“[Errno 8]”。Python冲突[Errno]消息
这个程序的目标是成为一个可执行文件,执行人员可以使用它来捕获我们公司拥有的网站的HTTP响应和URL重定向。
#!/bin/python
import urllib, urllib2, sys, logging, time
# Variables
s = time.strftime('%Y%m%d%H%M%S')
f = open("list.txt",'r')
# Logging
class Logger(object):
def __init__(self):
self.terminal = sys.stdout
self.log = open("assets_"+s+".txt", "a")
def write(self, message):
self.terminal.write(message)
self.log.write(message)
# Capture logging class
sys.stdout = Logger()
# Text file header
print "ASSET, STATUS, REDIRECT, DATE/TIME"
# Feed program 16,000 URLs
for url in f.readlines():
try:
http_connection = 'http://' + (url)
connection = urllib2.urlopen(http_connection)
print (url).rstrip("\n"), ",", connection.getcode(), ",", connection.geturl(), ",", (s)
connection.close()
except urllib2.URLError as e:
print e.reason
确实[这个问题](http://stackoverflow.com/questions/4847649/opening-websites-using-urllib2-from-behind-corporate-firewall-11004-getaddrinf)帮助? – bbayles