problem using http proxy with and

Raymond Yee yee at
Sun Mar 12 01:48:59 CET 2000

I'm having problems with using python with a proxy server.  (In my case,
my proxy server is another PC on the other end of a WebGear Aviator Pro
wireless connection -- and the proxy server software is WinProxy 2.1 by
Ositis.) I'm running Python 1.52 for Win32 on Win98; PythonWin build

For example, if I run the following code (which is based on urllib
looking in the environment variable for proxy servers -- see ):

import os os.environ['http_proxy'] = ""

import urllib u = urllib.urlopen("") print print

I get the following output:

Proxy-agent: Ositis-WinProxy for WebGear Connection: close Pragma:
no-cache Cache-Control: no-cache Content-Type: text/html
Content-Encoding: 7bit Content-Length: 161

<HEAD><TITLE>403 Forbidden</TITLE></HEAD> <BODY><H1>403
Forbidden</H1> <P>The request was not properly formatted.  A
possible security risk detected.</P> </BODY>

I know that a module
( has been
written to deal with a number of problems in  When I run the
same code (replacing references to urllib replaced by urllib2, I get the
following error:

Traceback (innermost last):
  File "D:\Apps\Python\Pythonwin\pywin\framework\", line
310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\WINDOWS\Desktop\", line 5, in ?
    u = urllib2.urlopen("")
  File "D:\Apps\Python\Lib\", line 137, in urlopen
    return, data)
  File "D:\Apps\Python\Lib\", line 321, in open
    '_open', req)
  File "D:\Apps\Python\Lib\", line 300, in _call_chain
    result = apply(func, args)
  File "D:\Apps\Python\Lib\", line 735, in http_open
    return self.parent.error('http', req, fp, code, msg, hdrs)
  File "D:\Apps\Python\Lib\", line 347, in error
    return apply(self._call_chain, args)
  File "D:\Apps\Python\Lib\", line 300, in _call_chain
    result = apply(func, args)
  File "D:\Apps\Python\Lib\", line 426, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 403: Forbidden

What am I doing wrong?  I know that the proxy server works -- I have no
problems using either Netscape or IE with the proxy server set to  Moreover, the following Perl program works:

use LWP::UserAgent;

 $ua = new LWP::UserAgent;
 $ua->proxy(['http'] => '');

 $req = new HTTP::Request 'GET',"";;

 $res = $ua->request($req);
 print $res->content if $res->is_success;

Any insight would be much appreciated.

Thanks in advance from a Python newbie,

-Raymond Yee

More information about the Python-list mailing list