Proxy authentication required

G

gervaz

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
 
C

Chris Rebert

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
 
P

python

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.


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


Cheers,
Chris

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-id:passwd
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
 
G

gervaz

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.


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


Cheers,
Chris

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
 
G

gervaz

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top