AdelaZhu / pydelicious

Automatically exported from code.google.com/p/pydelicious
Other
0 stars 0 forks source link

Add support for proxy #29

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Test api on a system connected to internet through a proxy

What is the expected output? What do you see instead?

this error happens :
<urlopen error [Errno 10060] A connection attempt failed because the 
connected party did not properly respond after a period of time, or 
established connection failed because connected host has failed to 
respond>, 4 tries left.
<urlopen error [Errno 10060] A connection attempt failed because the 
connected party did not properly respond after a period of time, or 
established connection failed because connected host has failed to 
respond>, 3 tries left.
<urlopen error [Errno 10060] A connection attempt failed because the 
connected party did not properly respond after a period of time, or 
established connection failed because connected host has failed to 
respond>, 2 tries left.
<urlopen error [Errno 10060] A connection attempt failed because the 
connected party did not properly respond after a period of time, or 
established connection failed because connected host has failed to 
respond>, 1 tries left.
Traceback (most recent call last):
  File "play.py", line 49, in <module>
    pydelicious.get_popular(tag='programming')
  File "C:\Python26\lib\site-packages\pydelicious.py", line 929, in 
get_popular
    return getrss(tag=tag, popular=1)
  File "C:\Python26\lib\site-packages\pydelicious.py", line 913, in getrss
    return dlcs_rss_request(tag=tag, popular=popular, user=user, url=url)
  File "C:\Python26\lib\site-packages\pydelicious.py", line 414, in 
dlcs_rss_request
    rss = http_request(url).read()
  File "C:\Python26\lib\site-packages\pydelicious.py", line 225, in 
http_request
    "Unable to retrieve data at '%s', %s" % (url, e)

What version of the product are you using? On what operating system?
pydelicious-0.5.2-rc1.zip

Please provide any additional information below.

in my system , which connects to the internet via a proxy , this code works

proxy_support = urllib2.ProxyHandler({'http': 
'http://168.219.61.250:8080/'})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
response = urllib2.urlopen('http://python.org/')
html = response.read()
print html

Original issue reported on code.google.com by aman....@gmail.com on 20 Jul 2009 at 8:52

GoogleCodeExporter commented 9 years ago
Hello there

i tried some quick hacking 

if  i add the following code to http_Request, everything works ok

    proxy_support = urllib2.ProxyHandler( {'http': 'http://168.219.61.250:8080/'} /* 
my proxy */ )
    opener = urllib2.build_opener(proxy_support)
    urllib2.install_opener(opener)

so i guess it is not so difficult to add some api for setting the proxy 
configuration.

if its ok with you, i can contribute

Original comment by aman....@gmail.com on 20 Jul 2009 at 9:21

GoogleCodeExporter commented 9 years ago
had a quick look and added reading HTTP_PROXY from os env. if you have any 
ideas on
where you want to opener initialized you're welcome to write a patch.

Original comment by berend.v...@gmail.com on 11 Sep 2009 at 11:17

GoogleCodeExporter commented 9 years ago

Original comment by berend.v...@gmail.com on 11 Sep 2009 at 11:18

GoogleCodeExporter commented 9 years ago
sorry, forgot to close this.

Proxy support is added through the HTTP_PROXY environment variable, set it and 
the 
urllib2 opener gets an proxy handler added. 

Details:
Function pydelicious.build_api_opener accepts extra openers but this argument 
is 
unused within the package. The function itself just adds a HTTPErrorHandler 
instance 
and the proxy handler as described.
Use the extra_handlers argument in your own API initializer modelled after 
pydelicious.dlcs_api_opener, and then override the DeliciousAPI build_opener 
keyword 
with the custom version.

Original comment by berend.v...@gmail.com on 12 Feb 2010 at 7:15

GoogleCodeExporter commented 9 years ago
Sorry for re-opening this issue, but you will also need to set the HTTPS proxy 
to make it work behind corporate firewalls/proxies (which is simple):

if HTTP_PROXY:
        extra_handlers += ( urllib2.ProxyHandler( {'http': HTTP_PROXY, 'https': HTTP_PROXY} ), )

Original comment by cluppr...@gmail.com on 29 Jul 2010 at 9:15