Re: urllib fails to connect

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Edwin.Madari@VerizonWireless.com

    #1

    Re: urllib fails to connect

    jlist wrote:
    >
    I found out why. I set a proxy in IE and I didn't know
    ActiveState Python use IE proxy!
    I'm running ActiveState Python 2.5 on Windows XP. It used
    to work fine. Today however I get (10061, 'Connection refused')
    for any site I try with urllib.urlopen( ).
    switching to urllib2, installing the proxy opener, worked for me.
    here is the sample. variable names are self explanatory

    import urllib2
    proxy=urllib2.P roxyHandler({"h ttp":'http://'+proxyuser+':' +proxypass+'@'+ httpproxy})
    opener=urllib2. build_opener(pr oxy, urllib2.HTTPHan dler)
    urllib2.install _opener(opener)
    req = urllib2.Request (url, form, headers)
    fd = urllib2.urlopen (req)
    print fd.code, fd.info(), fd.read()

    regards
    Edwin


    The information contained in this message and any attachment may be
    proprietary, confidential, and privileged or subject to the work
    product doctrine and thus protected from disclosure. If the reader
    of this message is not the intended recipient, or an employee or
    agent responsible for delivering this message to the intended
    recipient, you are hereby notified that any dissemination,
    distribution or copying of this communication is strictly prohibited.
    If you have received this communication in error, please notify me
    immediately by replying to this message and deleting it and all
    copies and backups thereof. Thank you.


  • jlist

    #2
    Re: urllib fails to connect

    Thanks. My problem was not how to use a proxy server but how
    to not use the IE proxy :)

    BTW, I'm not a fan of the way urllib2 uses a proxy particularly.
    I think it's really unneccesarily complicated. I think it should be
    something like this:
    def urlopen(url, proxy='')

    And if you want to use a proxy, set one in the call.
    I found out why. I set a proxy in IE and I didn't know
    ActiveState Python use IE proxy!
    >
    I'm running ActiveState Python 2.5 on Windows XP. It used
    to work fine. Today however I get (10061, 'Connection refused')
    for any site I try with urllib.urlopen( ).
    >
    switching to urllib2, installing the proxy opener, worked for me.
    here is the sample. variable names are self explanatory

    import urllib2
    proxy=urllib2.P roxyHandler({"h ttp":'http://'+proxyuser+':' +proxypass+'@'+ httpproxy})
    opener=urllib2. build_opener(pr oxy, urllib2.HTTPHan dler)
    urllib2.install _opener(opener)
    req = urllib2.Request (url, form, headers)
    fd = urllib2.urlopen (req)
    print fd.code, fd.info(), fd.read()

    regards
    Edwin


    The information contained in this message and any attachment may be
    proprietary, confidential, and privileged or subject to the work
    product doctrine and thus protected from disclosure. If the reader
    of this message is not the intended recipient, or an employee or
    agent responsible for delivering this message to the intended
    recipient, you are hereby notified that any dissemination,
    distribution or copying of this communication is strictly prohibited.
    If you have received this communication in error, please notify me
    immediately by replying to this message and deleting it and all
    copies and backups thereof. Thank you.



    Comment

    Working...