url lib

C

CSUIDL PROGRAMMEr

Hello
I am a novice python progammer

I am just writing a script that will automatically write my /etc/
yum.repos.d/* files in linux.

the problem is i am trying to connect to a secure repo and pass
username and password to the baseurl .

here is the baseurl
baseurl=http://USERNAME:[email protected]/yum/6.1/../../../.

I have tried using the urllib2 in python

the code i tried was
req=urllib2.Request("http://USERNAME:[email protected]/cell/yum/6.1/
base)
try: urllib2.urlopen(req)
except urllib2.URLError,e:

Where Username:pASSWORD are speciefied by user

The Error i got was
File "/usr/lib/python2.4/urllib2.py", line 130, in urlopen
return _opener.open(url, data)
File "/usr/lib/python2.4/urllib2.py", line 358, in open
response = self._open(req, data)
File "/usr/lib/python2.4/urllib2.py", line 376, in _open
'_open', req)
File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain
result = func(*args)
File "/usr/lib/python2.4/urllib2.py", line 1021, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib/python2.4/urllib2.py", line 980, in do_open
h = http_class(host) # will parse host:port
File "/usr/lib/python2.4/httplib.py", line 592, in __init__
self._set_hostport(host, port)
File "/usr/lib/python2.4/httplib.py", line 604, in _set_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: '(e-mail address removed)'

How can i connect to the site with password?? Do i have to implement
the ssl certification??
 
C

Chris Rebert

Hello
I am a novice python progammer

I am just writing a script that will automatically write my /etc/
yum.repos.d/* files in linux.

the problem is i am trying to connect to a secure repo and pass
username and password to the baseurl .

here is the baseurl
baseurl=http://USERNAME:[email protected]/yum/6.1/../../../.

I have tried using the urllib2 in python

the code i tried was
req=urllib2.Request("http://USERNAME:[email protected]/cell/yum/6.1/
base)
try: urllib2.urlopen(req)
except urllib2.URLError,e:

Where Username:pASSWORD are speciefied by user

The Error i got was
File "/usr/lib/python2.4/urllib2.py", line 130, in urlopen
   return _opener.open(url, data)
 File "/usr/lib/python2.4/urllib2.py", line 358, in open
   response = self._open(req, data)
 File "/usr/lib/python2.4/urllib2.py", line 376, in _open
   '_open', req)
 File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain
   result = func(*args)
 File "/usr/lib/python2.4/urllib2.py", line 1021, in http_open
   return self.do_open(httplib.HTTPConnection, req)
 File "/usr/lib/python2.4/urllib2.py", line 980, in do_open
   h = http_class(host) # will parse host:port
 File "/usr/lib/python2.4/httplib.py", line 592, in __init__
   self._set_hostport(host, port)
 File "/usr/lib/python2.4/httplib.py", line 604, in _set_hostport
   raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: '(e-mail address removed)'

How can i connect to the site with password?? Do i have to implement
the ssl certification??

Not bloody likely since your the URL's protocol is HTTP and not HTTPS.

Python doesn't handle username-password in the URL itself like you're
using. You specify it separately instead.

See the HTTPBasicAuthHandler, HTTPDigestAuthHandler, and
HTTPPasswordMgrWithDefaultRealm classes in urllib2, and the "Use of
Basic HTTP Authentication" example in the urllib2 docs -
http://docs.python.org/library/urllib2.html

Cheers,
Chris
 

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

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top