problem with urllib
hii everyone I am new to python programming.And i started implementing a http client using urllib in which i was facing a problem with proxy support.i was behind a proxy server and need to use proxy of format 10.1.2.21:8080 to connect to internet.when i used this with proxyhandler of urllib i got errors showing invalid proxy.can someone help me out plzzz. Regards venkat. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with urllib
This was the code i executed. >>> proxies={'http':'10.1.2.21:9090'} >>> opener = urllib.request.FancyURLopener(proxies) >>> f = opener.open("http://www.python.org";) Exception AttributeError: AttributeError("'FancyURLopener' object has no attribute 'tempcache'",) in > ignored Traceback (most recent call last): File "", line 1, in f = opener.open("http://www.python.org";) File "C:\Python30\lib\urllib\request.py", line 1439, in open return self.open_unknown_proxy(proxy, fullurl, data) File "C:\Python30\lib\urllib\request.py", line 1458, in open_unknown_proxy raise IOError('url error', 'invalid proxy for %s' % type, proxy) IOError: [Errno url error] invalid proxy for http: '10.1.2.21:9090' I know that url has to be used in proxies list but my proxy address is 10.1.2.21:9090 and it is squid proxy server. Regards venkat On Wed, Apr 1, 2009 at 4:35 AM, Chris Rebert wrote: > 2009/3/31 venkat sanaka : > > hii everyone > > > > I am new to python programming.And i started implementing a http client > > using urllib in which > > i was facing a problem with proxy support.i was behind a proxy server and > > need to use > > proxy of format 10.1.2.21:8080 to connect to internet.when i used this > with > > proxyhandler > > of urllib i got errors showing invalid proxy.can someone help me out > plzzz. > > What errors exactly? People will need the error message and full > traceback in order to help you. > A copy of your code would also be necessary for anyone trying to help you. > > Cheers, > Chris > -- > I have a blog: > http://blog.rebertia.com > -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with urllib
Yeah I did i was getting the same error as i got without using http in the url. Regards venkat. On Wed, Apr 1, 2009 at 4:46 AM, Chris Rebert wrote: > > On Wed, Apr 1, 2009 at 4:35 AM, Chris Rebert wrote: > >> > >> 2009/3/31 venkat sanaka : > >> > hii everyone > >> > > >> > I am new to python programming.And i started implementing a http > client > >> > using urllib in which > >> > i was facing a problem with proxy support.i was behind a proxy server > >> > and > >> > need to use > >> > proxy of format 10.1.2.21:8080 to connect to internet.when i used > this > >> > with > >> > proxyhandler > >> > of urllib i got errors showing invalid proxy.can someone help me out > >> > plzzz. > >> > >> What errors exactly? People will need the error message and full > >> traceback in order to help you. > >> A copy of your code would also be necessary for anyone trying to help > you. > > On Tue, Mar 31, 2009 at 4:10 PM, venkat sanaka > wrote: > > This was the code i executed. > > > >>>> proxies={'http':'10.1.2.21:9090'} > >>>> opener = urllib.request.FancyURLopener(proxies) > >>>> f = opener.open("http://www.python.org";) > > > > Exception AttributeError: AttributeError("'FancyURLopener' object has no > > attribute 'tempcache'",) in > > ignored > > Traceback (most recent call last): > > File "", line 1, in > > f = opener.open("http://www.python.org";) > > File "C:\Python30\lib\urllib\request.py", line 1439, in open > > return self.open_unknown_proxy(proxy, fullurl, data) > > File "C:\Python30\lib\urllib\request.py", line 1458, in > open_unknown_proxy > > raise IOError('url error', 'invalid proxy for %s' % type, proxy) > > IOError: [Errno url error] invalid proxy for http: '10.1.2.21:9090' > > > > I know that url has to be used in proxies list but my proxy address is > > 10.1.2.21:9090 and it is squid proxy server. > > Have you tried including the protocol in the proxy URL as per the > module's examples? Like: > > proxy = {'http' : 'http://10.1.2.21:9090'} > f = urllib.urlopen("http://python.org";, proxies=proxy) > > Cheers, > Chris > > -- > I have a blog: > http://blog.rebertia.com > -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with urllib
The correct one was 10.1.2.21:9090.In my code i tried with all the possible ways and end up in getting no result.sry for that. For more clarity I will give proxy settings in mozilla as: Http proxy:10.1.2.21 port:9090 Regards venkat On Wed, Apr 1, 2009 at 5:37 AM, Emile van Sebille wrote: > venkat sanaka wrote: > >> Yeah I did i was getting the same error as i got without using http in the >> url. >> >> > In your first message you say you need to use proxy of format > 10.1.2.21:8080 -- but in your code example you've written and the > traceback shows '10.1.2.21:9090 <http://10.1.2.21:9090>' > > Which is right? > > Emile > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with urllib
Thanks for ur suggestions Terry.These are really helpful for a newbie like me in python programming. Regards Venkat On Wed, Apr 1, 2009 at 5:59 AM, Terry Reedy wrote: > venkat sanaka wrote: > >> This was the code i executed. >> >> >>> proxies={'http':'10.1.2.21:9090 <http://10.1.2.21:9090>'} >> >>> opener = urllib.request.FancyURLopener(proxies) >> >>> f = opener.open("http://www.python.org";) >> >> Exception AttributeError: AttributeError("'FancyURLopener' object has no >> attribute 'tempcache'",) in > > ignored >> Traceback (most recent call last): >> File "", line 1, in >>f = opener.open("http://www.python.org";) >> File "C:\Python30\lib\urllib\request.py", line 1439, in open >>return self.open_unknown_proxy(proxy, fullurl, data) >> File "C:\Python30\lib\urllib\request.py", line 1458, in >> open_unknown_proxy >>raise IOError('url error', 'invalid proxy for %s' % type, proxy) >> IOError: [Errno url error] invalid proxy for http: '10.1.2.21:9090 < >> http://10.1.2.21:9090>' >> > > If you do not understand the error message and the error is in Python code, > you can go look at the code in the file to get a better idea. In this case, > the 'raise' statement is almost certainly preceded by an if statement. See > what condition was checked that your input would fail. If necessary, you can > edit request.py to add print statements (what I would do, after copying to > request.bak) what args are actually passed to open_unknown_proxy. Or try > pdb (which I never have). > > >> I know that url has to be used in proxies list but my proxy address is >> 10.1.2.21:9090 <http://10.1.2.21:9090> and it is squid proxy server. >> >> Regards >> venkat >> >> On Wed, Apr 1, 2009 at 4:35 AM, Chris Rebert > c...@rebertia.com>> wrote: >> >>2009/3/31 venkat sanaka ><mailto:venkatsan...@gmail.com>>: >> > hii everyone >> > >> > I am new to python programming.And i started implementing a http >>client >> > using urllib in which >> > i was facing a problem with proxy support.i was behind a proxy >>server and >> > need to use >> > proxy of format 10.1.2.21:8080 <http://10.1.2.21:8080> to connect >>to internet.when i used this with >> > proxyhandler >> > of urllib i got errors showing invalid proxy.can someone help me >>out plzzz. >> >>What errors exactly? People will need the error message and full >>traceback in order to help you. >>A copy of your code would also be necessary for anyone trying to >>help you. >> >>Cheers, >>Chris >>-- >>I have a blog: >>http://blog.rebertia.com >> >> >> >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with urllib
Hello everyone I am happy that my code finally worked and got the expected result.i suppose the problem is with python 3 becoz i wrote the similar code with python 2.5 without explicitly mentioning the proxy and it worked.It has taken the system's proxy settings as given in the documentation.Thanks a lot for ur replies. Final code: >>>import urllib2 >>> opener = urllib2.build_opener() >>> opener.add_header = [('User-agent', 'Mozilla')] >>>res=opener.open('http://www.google.com') >>> print res.read() On Wed, Apr 1, 2009 at 5:59 AM, Terry Reedy wrote: > venkat sanaka wrote: > >> This was the code i executed. >> >> >>> proxies={'http':'10.1.2.21:9090 <http://10.1.2.21:9090>'} >> >>> opener = urllib.request.FancyURLopener(proxies) >> >>> f = opener.open("http://www.python.org";) >> >> Exception AttributeError: AttributeError("'FancyURLopener' object has no >> attribute 'tempcache'",) in > > ignored >> Traceback (most recent call last): >> File "", line 1, in >>f = opener.open("http://www.python.org";) >> File "C:\Python30\lib\urllib\request.py", line 1439, in open >>return self.open_unknown_proxy(proxy, fullurl, data) >> File "C:\Python30\lib\urllib\request.py", line 1458, in >> open_unknown_proxy >>raise IOError('url error', 'invalid proxy for %s' % type, proxy) >> IOError: [Errno url error] invalid proxy for http: '10.1.2.21:9090 < >> http://10.1.2.21:9090>' >> > > If you do not understand the error message and the error is in Python code, > you can go look at the code in the file to get a better idea. In this case, > the 'raise' statement is almost certainly preceded by an if statement. See > what condition was checked that your input would fail. If necessary, you can > edit request.py to add print statements (what I would do, after copying to > request.bak) what args are actually passed to open_unknown_proxy. Or try > pdb (which I never have). > > >> I know that url has to be used in proxies list but my proxy address is >> 10.1.2.21:9090 <http://10.1.2.21:9090> and it is squid proxy server. >> >> Regards >> venkat >> >> On Wed, Apr 1, 2009 at 4:35 AM, Chris Rebert > c...@rebertia.com>> wrote: >> >>2009/3/31 venkat sanaka ><mailto:venkatsan...@gmail.com>>: >> > hii everyone >> > >> > I am new to python programming.And i started implementing a http >>client >> > using urllib in which >> > i was facing a problem with proxy support.i was behind a proxy >>server and >> > need to use >> > proxy of format 10.1.2.21:8080 <http://10.1.2.21:8080> to connect >>to internet.when i used this with >> > proxyhandler >> > of urllib i got errors showing invalid proxy.can someone help me >>out plzzz. >> >>What errors exactly? People will need the error message and full >>traceback in order to help you. >>A copy of your code would also be necessary for anyone trying to >>help you. >> >>Cheers, >>Chris >>-- >>I have a blog: >>http://blog.rebertia.com >> >> >> >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
"str object is not callable" error
HIi everyone. i was using python/c api to call a python function from c and I know the name of the function which i want to call.Is there any way to do that?? This is the method i tried... for eg:This is the python function i wants to call. >>>def add(x): ... return x+10 This is my code in C: PyObject *result = NULL; int arg; PyObject *arglist; arg = 123; my_callback = "add"; arglist = Py_BuildValue("(i)", arg); result = PyObject_CallObject(my_callback, arglist); Py_DECREF(arglist); return result; I was getting a error like "str object is not callable".From the error i came to know that i was assigning "add" as a string which caused this error.Then how to make it a callable object?? Regards Venkat -- http://mail.python.org/mailman/listinfo/python-list