473,395 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.ProxyHandler({"http":'http://'+proxyuser+':'+proxypass+'@'+httpproxy})
opener=urllib2.build_opener(proxy, urllib2.HTTPHandler)
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.
Aug 20 '08 #1
1 1308
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.ProxyHandler({"http":'http://'+proxyuser+':'+proxypass+'@'+httpproxy})
opener=urllib2.build_opener(proxy, urllib2.HTTPHandler)
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.

Aug 21 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: C GIllespie | last post by:
Dear All, I'm having problems using the urllib module and was wondering if anyone could suggest a solution. The only thing I can thing of is that I'm using at university and my uni uses a...
11
by: Pater Maximus | last post by:
I am trying to implement the recipe listed at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/211886 However, I can not get to first base. When I try to run import urllib...
4
by: william | last post by:
I've got a strange problem on windows (not very familiar with that OS). I can ping a host, but cannot get it via urllib (see here under). I can even telnet the host on port 80. Thus network...
6
by: JabaPyth | last post by:
Hello, I'm trying to use the urllib module, but when i try urllib.urlopen, it gives me a socket error: >>import urllib >>print urllib.urlopen('http://www.google.com/').read() Traceback (most...
0
by: Ali.Sabil | last post by:
hello all, I just maybe hit a bug in both urllib and urllib2, actually urllib doesn't support proxy authentication, and if you setup the http_proxy env var to...
4
by: kgrafals | last post by:
Hi, I'm just trying to read from a webpage with urllib but I'm getting IOErrors. This is my code: import urllib sock = urllib.urlopen("http://www.google.com/") and this is the error:
5
by: supercooper | last post by:
I am downloading images using the script below. Sometimes it will go for 10 mins, sometimes 2 hours before timing out with the following error: Traceback (most recent call last): File...
5
by: John Nagle | last post by:
I thought I had all the timeout problems with urllib worked around, but no. socket.setdefaulttimeout is useful, but not always effective. I'm setting that to 15 seconds. If the host end won't...
5
by: jlist | last post by:
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().
2
by: Iain Dalton | last post by:
In Emacs, using run-python, import urllib urllib.urlopen('http://www.google.com/') results in this traceback: Traceback (most recent call last): File "<stdin>", line 1, in <module> File...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.