proxy in urlopen()

E

Egor Bolonev

how they define proxy in urlopen? i've tried

a=urlopen('url', proxies=('127.0.0.1:3128'))
a=urlopen('url', proxies='127.0.0.1:3128')

but it says there is an error

==================================
Traceback (most recent call last):
File "getlinks.py", line 3, in ?
a=urlopen('http://forum.octopusnet.lan/',
proxies='127.0.0.1:3128').read()
File "C:\Python23\lib\urllib.py", line 69, in urlopen
opener = FancyURLopener(proxies=proxies)
File "C:\Python23\lib\urllib.py", line 544, in __init__
URLopener.__init__(self, *args, **kwargs)
File "C:\Python23\lib\urllib.py", line 106, in __init__
assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
AssertionError: proxies must be a mapping
Exception exceptions.AttributeError: "FancyURLopener instance has no
attribute 'tempcache'" in <bound method FancyURLopener.__del__ of
<urllib.FancyURLopener instance at 0x00909210>> ignored
==================================
 
N

Nick Vargish

Egor Bolonev said:
AssertionError: proxies must be a mapping

This is telling you proxies must be a mapping type, in this case, a
dictionary. So try replacing:
a=urlopen('url', proxies=('127.0.0.1:3128'))

With this:

a=urlopen('url', proxies={ 'http': '127.0.0.1:3128' })

HTH,

Nick
 

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
474,197
Messages
2,571,042
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top