mysteries of urllib/urllib2

Ben Cartwright benc.nospam at gmail.com
Tue Jul 3 16:25:02 CEST 2007


On Jul 3, 9:43 am, Adrian Smith <adrian_p_sm... at yahoo.com> wrote:
> The following (pinched
> from Dive Into Python) seems to work perfectly in Idle, but falls at
> the final hurdle when run as a cgi script - can anyone suggest
> anything I may have overlooked?
>
> request = urllib2.Request(some_URL)
> request.add_header('User-Agent', 'some_plausible_string')
> opener = urllib2.build_opener()
> data = opener.open(request).read()

Most likely the account that cgi script is running as does not have
permissions to access the net. Check the traceback to be sure. Put
this at the top of your cgi script:

import cgitb; cgitb.enable()

--Ben




More information about the Python-list mailing list