473,730 Members | 2,215 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python Behind a Squid Corporate Proxy on Windows

Greetings, Pythonistas!

My employer has a Squid Proxy between my Python programs and The
Internet.

I've searched high-and-low, and can only find examples online of how
to do basic authentication to connect TO an external Web Server, but
not how to go THROUGH a (corporate) Proxy, thus my question here.
I've tried all sorts of permutations based on my findings, but
(obviously) nothing's working for me. I've come across conflicting
information, including that urllib2 can't/won't do what I'm needing,
though this statement was a couple years old.

I'm running Python 2.5 on Windows XP SP2 64-bit. The Proxy is Squid
(don't know what version, but can find out if this is relevant).

urllib2 grabs the Proxy info fine: 'http': 'http://webfilter.xyz.l ocal:
3128' (.getproxies()) . There's the obvious necessity of telling
"something" my ID/pass *somehow*.

An example of one iteration:

############### #######

import urllib2

proxy_handler = urllib2.ProxyHa ndler( { "http": "http://
myusername:@web filter.xyz.loca l:3128" } )
opener = urllib2.build_o pener( proxy_handler )

urllib2.install _opener( opener )

response = opener.open( "http://python.org" )

print response

############### #######

I've tried situations using HTTPPasswordMgr WithDefaultReal m and its
add_password method, also to no avail. (Again, THIS sort of thing
seems related to the -external- Web Server, _not_ going *through* a
Proxy. 'Course, I could be wrong. But if I am, I couldn't get this
to work, either. ;)

I've looked at what's happening with Wireshark; Py/my program/urllib2
makes the initial page request, Proxy replies HTTP Error 407: Proxy
Authentication Required, and Py/my program/urllib2 simply stops at
that, reporting the message/error.

Please forgive me; I've been programming in Python for a few years
now, but never had to deal with Web Proxies. I *have* tried to RTFMs,
but the "documentat ion" for non-basic stuffs with urllib2 is... uh...
well, I'm sure ye olde pro's know... :)
Cheers, and *any* help would be appreciated!
-Larry
Jul 17 '08 #1
6 4527
Err, the line above should be:

proxy_handler = urllib2.ProxyHa ndler( { "http": "http://
myusername:pa** ****@webfilter. xyz.local:3128" } )

(Sorry! :)
Jul 17 '08 #2
On Jul 17, 6:40*pm, Larry Hale <larz...@hotmai l.comwrote:
Err, the line above should be:

proxy_handler = urllib2.ProxyHa ndler( { "http": "http://
myusername:pass w...@webfilter. xyz.local:3128" } )

(Sorry! *:)
some old code I wrote to download public domain info for our company,
also through a squid proxy and this still works for me

import urllib2, urllib

proxy = urllib2.ProxyHa ndler({'http': 'http://
username:passwo rd@proxy_url:pr oxy_port'})
auth = urllib2.HTTPBas icAuthHandler()
opener = urllib2.build_o pener(proxy, auth, urllib2.HTTPHan dler)
urllib2.install _opener(opener)

conn = urllib2.urlopen ('http://python.org')
return_str = conn.read()

fp = open('python.ht ml','w').write( return_str)
Jul 18 '08 #3
Thank you so much for the reply, but alas: I get the same results.
(urllib2 makes the initial request, Squid replies "Error 407: Proxy
Authentication Required", which urllib2 dutifully fails on/raises said
error...)

I do appreciate your time, though! :)
-Larry
On Jul 18, 3:08*am, Chris <cwi...@gmail.c omwrote:
On Jul 17, 6:40*pm, Larry Hale <larz...@hotmai l.comwrote:
Err, the line above should be:
proxy_handler = urllib2.ProxyHa ndler( { "http": "http://
myusername:pass w...@webfilter. xyz.local:3128" } )
(Sorry! *:)

some old code I wrote to download public domain info for our company,
also through a squid proxy and this still works for me

import urllib2, urllib

proxy = urllib2.ProxyHa ndler({'http': 'http://
username:passwo rd@proxy_url:pr oxy_port'})
auth = urllib2.HTTPBas icAuthHandler()
opener = urllib2.build_o pener(proxy, auth, urllib2.HTTPHan dler)
urllib2.install _opener(opener)

conn = urllib2.urlopen ('http://python.org')
return_str = conn.read()

fp = open('python.ht ml','w').write( return_str)
Jul 18 '08 #4
Thank you so much for the reply, but alas: I get the same results.
(urllib2 makes the initial request, Squid replies "Error 407: Proxy
Authentication Required", which urllib2 dutifully fails on/raises said
error...)

I do appreciate your time, though! :)
-Larry
On Jul 18, 3:08*am, Chris <cwi...@gmail.c omwrote:
On Jul 17, 6:40*pm, Larry Hale <larz...@hotmai l.comwrote:
Err, the line above should be:
proxy_handler = urllib2.ProxyHa ndler( { "http": "http://
myusername:pass w...@webfilter. xyz.local:3128" } )
(Sorry! *:)

some old code I wrote to download public domain info for our company,
also through a squid proxy and this still works for me

import urllib2, urllib

proxy = urllib2.ProxyHa ndler({'http': 'http://
username:passwo rd@proxy_url:pr oxy_port'})
auth = urllib2.HTTPBas icAuthHandler()
opener = urllib2.build_o pener(proxy, auth, urllib2.HTTPHan dler)
urllib2.install _opener(opener)

conn = urllib2.urlopen ('http://python.org')
return_str = conn.read()

fp = open('python.ht ml','w').write( return_str)
Jul 18 '08 #5
Thank you so much for the reply, but alas: I get the same results.
(urllib2 makes the initial request, Squid replies "Error 407: Proxy
Authentication Required", which urllib2 dutifully fails on/raises said
error...)

I do appreciate your time, though! :)
-Larry
On Jul 18, 3:08*am, Chris <cwi...@gmail.c omwrote:
On Jul 17, 6:40*pm, Larry Hale <larz...@hotmai l.comwrote:
Err, the line above should be:
proxy_handler = urllib2.ProxyHa ndler( { "http": "http://
myusername:pass w...@webfilter. xyz.local:3128" } )
(Sorry! *:)

some old code I wrote to download public domain info for our company,
also through a squid proxy and this still works for me

import urllib2, urllib

proxy = urllib2.ProxyHa ndler({'http': 'http://
username:passwo rd@proxy_url:pr oxy_port'})
auth = urllib2.HTTPBas icAuthHandler()
opener = urllib2.build_o pener(proxy, auth, urllib2.HTTPHan dler)
urllib2.install _opener(opener)

conn = urllib2.urlopen ('http://python.org')
return_str = conn.read()

fp = open('python.ht ml','w').write( return_str)
Jul 18 '08 #6
Hi,

do you manage to go through the proxy? I'm having the same problem
with error 407. I've tried many solutions from the web but it always
show the same error. So, if you solved your problem, please, post it
here.

Thanks
Danilo

On 18 jul, 15:43, Larry Hale <larz...@hotmai l.comwrote:
Thank you so much for the reply, but alas: I get the same results.
(urllib2 makes the initial request,Squidre plies "Error 407:Proxy
Authentication Required", which urllib2 dutifully fails on/raises said
error...)

I do appreciate your time, though! :)
-Larry

On Jul 18, 3:08 am, Chris <cwi...@gmail.c omwrote:
On Jul 17, 6:40 pm, Larry Hale <larz...@hotmai l.comwrote:
Err, the line above should be:
proxy_handler = urllib2.ProxyHa ndler( { "http": "http://
myusername:pass w...@webfilter. xyz.local:3128" } )
(Sorry! :)
some old code I wrote to download public domain info for our company,
also through asquidproxyand this still works for me
import urllib2, urllib
proxy= urllib2.ProxyHa ndler({'http': 'http://
username:passwo rd@proxy_url:pr oxy_port'})
auth = urllib2.HTTPBas icAuthHandler()
opener = urllib2.build_o pener(proxy, auth, urllib2.HTTPHan dler)
urllib2.install _opener(opener)
conn = urllib2.urlopen ('http://python.org')
return_str = conn.read()
fp = open('python.ht ml','w').write( return_str)
Aug 21 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
11789
by: Chris Gray | last post by:
Is there such a beast? In particular, I'm looking for a production-quality proxy server fully compliant with HTTP/1.1 written in Python. If there isn't, is there anything that comes close? Thanks for any help you can throw my way, Chris Gray "Okey dokey.. free my mind. Right, no problem, free my mind, free my mind,
3
5749
by: Muhammad Ali | last post by:
Hi, I am a python newbie but have c/c++ experience. I have a small Lan (windows 2000 sever + some win 98 machines). The win2k connects to the internet using a dial-up connection. What i need to do is to allow users, who would come from win98 machines to use internet for a specific amount of time. For example, if userA has been alloted twohours then he can no longer access internet from the win98 machine after expiring those two hours.
3
3815
by: Thomas Miller | last post by:
Is there ANY way for a windows app to consume a web service by going through a SOCKS proxy? This is a MUST for me because the windows app I am building will be deployed to many corporate clients who are behind SOCKS proxies. My app also has corporate clients that are behind a HTTP proxy. Is there a way for the windows app to consume a web service through a HTTP proxy? Please post any relevant code you have, THANKS!
1
2872
by: Leonardo Ivan Torres Ochoa | last post by:
Hello friends I have a program client done in C # that invokes to a Web service, the program client uses proxy squid, but this return Timeout returns Any idea ? Thank you .. Leonardo..
0
1845
by: .NET Undertaker | last post by:
Hi I have windows application(C#) that consumes a Web Service.Now my problem is with clients whom installed my application and use SQUId 2.5/Stable 4 , they keep getting HTTP error 407 proxy authentication failed. here is what I have done I am pssing the proxy username/password and domain with my application Web Service proxy with luck @ all , all other kind of proxies work (ISA and all)
0
1340
by: phil.a.jenkins | last post by:
Hopefully someone can provide a solution to this rather annoying problem - we have a Cocoon pipeline which ends thus: <!-- build the sql for insert and final stage of select --> T1 <map:transform type="xslt" src="stylesheets/buildsql2.xsl"/> <!-- run the sql --> <map:transform type="sql"> <map:parameter name="*****" value="****"/> </map:transform>
5
2998
by: thorley | last post by:
Greetings, I'm interested in a simple content-based internet firewall/filter, similar to dansguardian (http://dansguardian.org/), but written in python, and for windows. I assumed such a project would already exist, but my searches on freshmeat, and google turned up empty. I would be interested in starting my own project if necessary, so I have two questions: 1) Does any one no of such a project?
0
1995
by: Marcus Ogden | last post by:
Hello, A client of ours using the Squid proxy server (version 2.5.STABLE6-3.4E.12.1) on Red Hat Enterprise Linux 4 is experiencing a problem when running our .NET 2.0 client application, which communicates with a .NET 2.0 web service on our server. When our client application sends an HTTP 1.1 request through the Squid proxy to our server, it receives the error:
1
3741
by: karthikeyanck | last post by:
I 've installed squid proxy server on my Ubuntu machine (Vmware image) It has no direct internet connection and is on a private n/w (192.168). It uses another proxy server to reach the internet. it's on another network Now when i configure other machines to point this Ubuntu as their proxy server it wouldnot connect to the internet ! http_port 3128 acl home_net src 192.168.209.0/255.255.255.0
0
8770
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9301
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9229
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8184
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6725
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4543
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.