dealing with a proxy

David Fisher python at rose164.wuh.wustl.edu
Fri Mar 3 03:42:10 CET 2000


urllib has proxy support built-in, but not documented.

>>> import urllib
>>> proxy = { 'http': r'http://192.168.1.1:3128'}  #squid proxy on my local
network
>>> u = urllib.URLopener(proxies = proxy)
>>> f = u.open(r'http://www.python.org')
>>> print f.read()
<HTML>
<!-- THIS PAGE IS AUTOMATICALLY GENERATED.  DO NOT EDIT. -->
<!-- Mon Feb 28 11:00:24 2000 -->
<!-- USING HT2HTML 1.1 -->
<!-- SEE http://www.python.org/~bwarsaw/software/pyware.html -->
<!-- User-specified headers:
Title: Python Language Website

etc, etc, etc
you can add other proxies for ftp, et al. , i haven't done it, but I'm know
for my blind faith
david
----- Original Message -----
From: "Steven Adams" <sada7681 at mail.usyd.edu.au>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Thursday, March 02, 2000 7:03 PM
Subject: Re: dealing with a proxy


> hmm, I think I've found it,
>
> do i first:
>
> h = httplib.HTTP(proxyhost, proxyport)
>
> then send requests
>
> h.putrequest('GET', 'http://somehwere.somedomain')
>
> is there a better method?






More information about the Python-list mailing list