Найти - Пользователи
Полная версия: proxy iis7
Начало » Python для новичков » proxy iis7
1
legi0ner
пытаюсь получить http страничку.
import urllib2
proxy = "login:pass@proxy:8080"
try:
	proxy_handler = urllib2.ProxyHandler({'http': proxy})
	opener = urllib2.build_opener(proxy_handler)
	opener.addheaders = [('User-agent', 'Mozilla/5.0')]
	urllib2.install_opener(opener)
	req=urllib2.Request('http://www.google.com')
	sock=urllib2.urlopen(req)
except urllib2.HTTPError, e:
	print u'Код ошибки: ', e.code
except Exception, detail:
    print u"Ошибка:", detail
print sock.headers
получаю от сервера Connection: close
Content-Type: text/html
Last-Modified: Mon, 26 Mar 2012 08:10:29 GMT
Accept-Ranges: bytes
ETag: "8c6d93e827bcd1:0"
Server: Microsoft-IIS/7.5
Date: Thu, 01 Nov 2012 04:31:54 GMT
Connection: close
Content-Length: 689
и страничку HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x
html1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>IIS7</title>
<style type="text/css">
<!--
body {
        color:#000000;
        background-color:#B3B3B3;
        margin:0;
}
#container {
        margin-left:auto;
        margin-right:auto;
        text-align:center;
        }
a img {
        border:none;
}
-->
</style>
</head>
<body>
<div id="container">
<a href="http://go.microsoft.com/fwlink/?linkid=66138&amp;clcid=0x409"><img src=
"welcome.png" alt="IIS7" width="571" height="411" /></a>
</div>
</body>
</html>
Буду рад любой помощи
odnochlen
Дам совет, который я даю во всех темах про http - выкин ущербный urllib и возьми grab или requests.

В grab колдовать с user agent не придется, там встроен рандом пул юзер агентов.

Дальше, заголовок сервера ты выложит, заодно хорошо бы и заголовок клиента.
legi0ner
Пробую с помощью grab
from grab import Grab, GrabError
g = Grab()
g.setup(proxy='proxy:8080', proxy_userpwd="login:pass", proxy_type='http' )
g.go('http://google.ru', log_file='log.txt')
на выходе получаю ошибку
Technical Information (for support personnel)
Error Code: 407 Proxy Authentication Required. The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied. (12209)
IP Address: 195.2.214.85
Date: 02.11.2012 4:12:02
Server: proxy-node3.cap.ru
Source: proxy
From nobody Fri Nov 02 08:41:49 2012
Via: 1.1 PROXY-NODE3
Proxy-Authenticate: Negotiate
Proxy-Authenticate: Kerberos
Proxy-Authenticate: NTLM
Connection: Keep-Alive
Proxy-Connection: Keep-Alive
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html
Content-Length: 4109
PooH
NTLM авторизация, питон такое из коробки не умеет.
вроде есть проект
я когда-то давно решал через NTLM Authorization Proxy Server
Andrejus
у меня работал вариант с переменной среды HTTP_PROXY,
взятый отсюда
Your text to link here…
legi0ner
Спасибо всем за помощь) пока все то же самое.
legi0ner
замучился я с этим прокси. решил проблему установив cntlm.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB