Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Proxy authentication required

Reply
Thread Tools

Proxy authentication required

 
 
gervaz
Guest
Posts: n/a
 
      03-21-2011
Hi all,
I've got to download some web pages but I'm behind a proxy. So far
this is what I've used without any successful result receiving the
error: "urllib.error.HTTPError: HTTP Error 407: Proxy Authentication
Required ( The ISA Server requires auth
orization to fulfill the request. Access to the Web Proxy filter is
denied. )":

hc = urllib.request.HTTPCookieProcessor()
hp = urllib.request.ProxyHandler({"http": "10.242.38.251:80",
"username": "domain\username", "password": "password"})
opener = urllib.request.build_opener(hc, hp)
urllib.request.urlopen("http://www.google.it/")

Any suggestion?

Thanks,

Mattia
 
Reply With Quote
 
 
 
 
Chris Rebert
Guest
Posts: n/a
 
      03-21-2011
On Mon, Mar 21, 2011 at 2:38 AM, gervaz <(E-Mail Removed)> wrote:
> Hi all,
> I've got to download some web pages but I'm behind a proxy. So far
> this is what I've used without any successful result receiving the
> error: "urllib.error.HTTPError: HTTP Error 407: Proxy Authentication
> Required ( The ISA Server requires auth
> orization to fulfill the request. Access to the Web Proxy filter is
> denied. *)":
>
> hc = urllib.request.HTTPCookieProcessor()
> hp = urllib.request.ProxyHandler({"http": "10.242.38.251:80",
> "username": "domain\username", "password": "password"})


Remember that backslash is used for string escapes in Python; so that
should be "domain\\username" in order to get 1 literal backslash. I
suspect this is the cause of your proxy authentication problem.

> opener = urllib.request.build_opener(hc, hp)


Are you sure that's the right order for the handlers? (I don't know myself.)

> urllib.request.urlopen("http://www.google.it/")


Cheers,
Chris
--
Windows, Y U use backslash for stuff!?
http://blog.rebertia.com
 
Reply With Quote
 
 
 
 
python
Guest
Posts: n/a
 
      03-22-2011
On Mar 21, 7:02*pm, Chris Rebert <(E-Mail Removed)> wrote:
> On Mon, Mar 21, 2011 at 2:38 AM, gervaz <(E-Mail Removed)> wrote:
> > Hi all,
> > I've got to download some web pages but I'm behind a proxy. So far
> > this is what I've used without any successful result receiving the
> > error: "urllib.error.HTTPError: HTTP Error 407: Proxy Authentication
> > Required ( The ISA Server requires auth
> > orization to fulfill the request. Access to the Web Proxy filter is
> > denied. *)":

>
> > hc = urllib.request.HTTPCookieProcessor()
> > hp = urllib.request.ProxyHandler({"http": "10.242.38.251:80",
> > "username": "domain\username", "password": "password"})

>
> Remember that backslash is used for string escapes in Python; so that
> should be "domain\\username" in order to get 1 literal backslash. I
> suspect this is the cause of your proxy authentication problem.
>
> > opener = urllib.request.build_opener(hc, hp)

>
> Are you sure that's the right order for the handlers? (I don't know myself.)
>
> > urllib.request.urlopen("http://www.google.it/")

>
> Cheers,
> Chris
> --
> Windows, Y U use backslash for stuff!?http://blog.rebertia.com


did this a long time ago when behind a corporate proxy server worked
then might be a start for you
I am fuzzy on the details.

import httplib
import base64
import getpass
def getWebPage(userName='YourUserName',httpPage='http://
weather.noaa.gov/weather/current/KRIC.html',outFilePath=None):
# 1. connect to the proxy
h1 = httplib.HTTP("proxyconf",)

# 2. give the absolute URL in the request
h1.putrequest('GET', 'http://weather.noaa.gov/weather/current/
KRIC.html')

h1.putheader('Accept', 'text/html')
h1.putheader('Accept', 'text/plain')
password = getpass.getpass()
# 3. set the header with a base64 encoding of user-idasswd
userString = "%s:%s" % (userName,password)
auth = "Basic " + base64.encodestring(userString)
h1.putheader('Proxy-Authorization', auth)
h1.endheaders()

# 4. get the page
errcode, errmsg, headers = h1.getreply()

print errcode
print errmsg
print headers

f=h1.getfile()
if(not outFilePath):
for line in f.readlines():
print line
else:
try:
outFile = open(outFilePath,'w')
# yada yaha
 
Reply With Quote
 
gervaz
Guest
Posts: n/a
 
      03-22-2011
On 22 Mar, 00:02, Chris Rebert <(E-Mail Removed)> wrote:
> On Mon, Mar 21, 2011 at 2:38 AM, gervaz <(E-Mail Removed)> wrote:
> > Hi all,
> > I've got to download some web pages but I'm behind a proxy. So far
> > this is what I've used without any successful result receiving the
> > error: "urllib.error.HTTPError: HTTP Error 407: Proxy Authentication
> > Required ( The ISA Server requires auth
> > orization to fulfill the request. Access to the Web Proxy filter is
> > denied. *)":

>
> > hc = urllib.request.HTTPCookieProcessor()
> > hp = urllib.request.ProxyHandler({"http": "10.242.38.251:80",
> > "username": "domain\username", "password": "password"})

>
> Remember that backslash is used for string escapes in Python; so that
> should be "domain\\username" in order to get 1 literal backslash. I
> suspect this is the cause of your proxy authentication problem.
>
> > opener = urllib.request.build_opener(hc, hp)

>
> Are you sure that's the right order for the handlers? (I don't know myself.)
>
> > urllib.request.urlopen("http://www.google.it/")

>
> Cheers,
> Chris
> --
> Windows, Y U use backslash for stuff!?http://blog.rebertia.com


Hi Cris,
I had already tested the solution with the '\\' but the result is the
same. As per the arguments order, build_opener thakes *handlers as
argument so no problem.

Mattia
 
Reply With Quote
 
gervaz
Guest
Posts: n/a
 
      03-22-2011
On 22 Mar, 09:34, gervaz <(E-Mail Removed)> wrote:
> On 22 Mar, 00:02, Chris Rebert <(E-Mail Removed)> wrote:
>
>
>
>
>
> > On Mon, Mar 21, 2011 at 2:38 AM, gervaz <(E-Mail Removed)> wrote:
> > > Hi all,
> > > I've got to download some web pages but I'm behind a proxy. So far
> > > this is what I've used without any successful result receiving the
> > > error: "urllib.error.HTTPError: HTTP Error 407: Proxy Authentication
> > > Required ( The ISA Server requires auth
> > > orization to fulfill the request. Access to the Web Proxy filter is
> > > denied. *)":

>
> > > hc = urllib.request.HTTPCookieProcessor()
> > > hp = urllib.request.ProxyHandler({"http": "10.242.38.251:80",
> > > "username": "domain\username", "password": "password"})

>
> > Remember that backslash is used for string escapes in Python; so that
> > should be "domain\\username" in order to get 1 literal backslash. I
> > suspect this is the cause of your proxy authentication problem.

>
> > > opener = urllib.request.build_opener(hc, hp)

>
> > Are you sure that's the right order for the handlers? (I don't know myself.)

>
> > > urllib.request.urlopen("http://www.google.it/")

>
> > Cheers,
> > Chris
> > --
> > Windows, Y U use backslash for stuff!?http://blog.rebertia.com

>
> Hi Cris,
> I had already tested the solution with the '\\' but the result is the
> same. As per the arguments order, build_opener thakes *handlers as
> argument so no problem.
>
> Mattia- Nascondi testo citato
>
> - Mostra testo citato -


Further investigating the issue the proxy needs NTLM authentication,
for that reason no solution so far works. I'm using py3.

Thanks,

Mattia
 
Reply With Quote
 
Chris Rebert
Guest
Posts: n/a
 
      03-23-2011
On Tue, Mar 22, 2011 at 3:57 AM, gervaz <(E-Mail Removed)> wrote:
> On 22 Mar, 09:34, gervaz <(E-Mail Removed)> wrote:
>> On 22 Mar, 00:02, Chris Rebert <(E-Mail Removed)> wrote:
>> > On Mon, Mar 21, 2011 at 2:38 AM, gervaz <(E-Mail Removed)> wrote:
>> > > Hi all,
>> > > I've got to download some web pages but I'm behind a proxy. So far
>> > > this is what I've used without any successful result receiving the
>> > > error: "urllib.error.HTTPError: HTTP Error 407: Proxy Authentication
>> > > Required ( The ISA Server requires auth
>> > > orization to fulfill the request. Access to the Web Proxy filter is
>> > > denied. *)":

>>
>> > > hc = urllib.request.HTTPCookieProcessor()
>> > > hp = urllib.request.ProxyHandler({"http": "10.242.38.251:80",
>> > > "username": "domain\username", "password": "password"})

<snip>
> Further investigating the issue the proxy needs NTLM authentication,
> for that reason no solution so far works. I'm using py3.


pycurl apparently supports NTLM proxies, but it's not Python 3-compatible:
http://pycurl.sourceforge.net/

python-ntlm seems to be Python 3-compatible, but I don't know whether
it handles proxying:
http://code.google.com/p/python-ntlm/

Cheers,
Chris
--
http://blog.rebertia.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTP Status 407: Proxy Authentication Required Sau ASP .Net Web Services 2 12-15-2009 11:08 AM
Proxy Authentication Required - Error 407 UJ ASP .Net Web Services 0 08-15-2006 06:23 PM
407 Proxy authentication required? Ily ASP .Net 1 10-31-2005 04:44 PM
request failed with HTTP status 407: Proxy Authentication Required Scott O'Donnell ASP .Net Web Services 0 02-14-2005 12:23 AM
Proxy authentication required samy coco via .NET 247 ASP .Net Web Services 1 04-23-2004 07:28 AM



Advertisments