FAQ
Hello,

I want to create a client to access a webpage. But when I access it
interactively there is a dialog box
which ask for login and password.
I want to access it in batch via python but I could only found a basic
example:
#||!/bin/env|| ||python|
#|| ||-*-|| ||coding:|| ||utf-8|| ||-*-|
import| urllib2
reponse|=| urllib2.|urlopen|(|'||http||:||/||/||www||.||kernel||.||org||/||'|)
xhtmldata|=| reponse.|read|()
for| num,ligne|in| |enumerate|(xhtmldata.|splitlines|()) :
print| |"||%04d|| ||-|| ||%s||"||%|(num,ligne)
I want to provide login and password via python code. The web adress is
like http://website.com:8081/ddts/ddts_main.
If you have link it is welcome!

Regards
Karim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110128/6fa5027c/attachment.html>

Search Discussions

  • Vince Spicer at Jan 28, 2011 at 10:05 pm
    You may want to look at httplib2

    http://code.google.com/p/httplib2/

    This great module makes auth very simple

    Vince
    On Fri, Jan 28, 2011 at 3:54 PM, Karim wrote:


    Hello,

    I want to create a client to access a webpage. But when I access it
    interactively there is a dialog box
    which ask for login and password.
    I want to access it in batch via python but I could only found a basic
    example:

    #!/bin/env python# -*- coding: utf-8 -*-
    import urllib2
    reponse = urllib2.urlopen('http://www.kernel.org/')
    xhtmldata = reponse.read()for num,ligne in enumerate(xhtmldata.splitlines()) :
    print "%04d - %s"%(num,ligne)

    I want to provide login and password via python code. The web adress is
    like http://website.com:8081/ddts/ddts_main.
    If you have link it is welcome!

    Regards
    Karim

    _______________________________________________
    Tutor maillist - Tutor at python.org
    To unsubscribe or change subscription options:
    http://mail.python.org/mailman/listinfo/tutor

    --
    Vince Spicer
    Developer
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/tutor/attachments/20110128/773a7e42/attachment.html>
  • Karim at Jan 28, 2011 at 10:28 pm
    Vince I saw your answer on the related subject fron October 2010 : *Re:
    [Tutor] Requesting restricted URL (further authentication requested)*.

    Thanks
    Karim
    On 01/28/2011 11:05 PM, Vince Spicer wrote:
    You may want to look at httplib2

    http://code.google.com/p/httplib2/

    This great module makes auth very simple

    Vince

    On Fri, Jan 28, 2011 at 3:54 PM, Karim <karim.liateni at free.fr
    wrote:


    Hello,

    I want to create a client to access a webpage. But when I access
    it interactively there is a dialog box
    which ask for login and password.
    I want to access it in batch via python but I could only found a
    basic example:
    #||!/bin/env|| ||python|
    #|| ||-*-|| ||coding:|| ||utf-8|| ||-*-|
    import| urllib2
    reponse|=| urllib2.|urlopen|(|'||http||:||/||/||www||.||kernel||.||org||/||'|)
    xhtmldata|=| reponse.|read|()
    for| num,ligne|in| |enumerate|(xhtmldata.|splitlines|()) :
    print| |"||%04d|| ||-|| ||%s||"||%|(num,ligne)
    I want to provide login and password via python code. The web
    adress is like http://website.com:8081/ddts/ddts_main.
    If you have link it is welcome!

    Regards
    Karim

    _______________________________________________
    Tutor maillist - Tutor at python.org <mailto:Tutor at python.org>
    To unsubscribe or change subscription options:
    http://mail.python.org/mailman/listinfo/tutor




    --
    Vince Spicer
    Developer
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/tutor/attachments/20110128/77d28780/attachment-0001.html>
  • Ian douglas at Jan 28, 2011 at 10:15 pm
    If it's HTTP basic_auth, you could try this method too:

    http://username:password at domain.com/page.html

    On 01/28/2011 01:54 PM, Karim wrote:

    Hello,

    I want to create a client to access a webpage. But when I access it
    interactively there is a dialog box
    which ask for login and password.
    I want to access it in batch via python but I could only found a basic
    example:
    #||!/bin/env|| ||python|
    #|| ||-*-|| ||coding:|| ||utf-8|| ||-*-|
    import| urllib2
    reponse|=| urllib2.|urlopen|(|'||http||:||/||/||www||.||kernel||.||org||/||'|)
    xhtmldata|=| reponse.|read|()
    for| num,ligne|in| |enumerate|(xhtmldata.|splitlines|()) :
    print| |"||%04d|| ||-|| ||%s||"||%|(num,ligne)
    I want to provide login and password via python code. The web adress
    is like http://website.com:8081/ddts/ddts_main.
    If you have link it is welcome!

    Regards
    Karim


    _______________________________________________
    Tutor maillist - Tutor at python.org
    To unsubscribe or change subscription options:
    http://mail.python.org/mailman/listinfo/tutor
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/tutor/attachments/20110128/78db2f31/attachment.html>
  • Karim at Jan 28, 2011 at 10:33 pm
    Thanks Ian!

    This is a simple one!

    I found this other way said more flexible, I must check it too:

    *import urllib

    class myURLOpener(urllib.FancyURLopener):
    def setpasswd(self, user, passwd):
    self.__user = user
    self.__passwd = passwd

    def prompt_user_passwd(self, host, realm):
    return self.__user, self.__passwd

    urlopener = myURLOpener()
    urlopener.setpasswd("mulder", "trustno1")*

    Basically, we must subclass **urllib.FancyURLopener** and override
    **prompt_user_passwd().

    **Regards
    Karim
    **
    ** On 01/28/2011 11:15 PM, ian douglas wrote:
    If it's HTTP basic_auth, you could try this method too:

    http://username:password at domain.com/page.html

    On 01/28/2011 01:54 PM, Karim wrote:

    Hello,

    I want to create a client to access a webpage. But when I access it
    interactively there is a dialog box
    which ask for login and password.
    I want to access it in batch via python but I could only found a
    basic example:
    #||!/bin/env|| ||python|
    #|| ||-*-|| ||coding:|| ||utf-8|| ||-*-|
    import| urllib2
    reponse|=| urllib2.|urlopen|(|'||http||:||/||/||www||.||kernel||.||org||/||'|)
    xhtmldata|=| reponse.|read|()
    for| num,ligne|in| |enumerate|(xhtmldata.|splitlines|()) :
    print| |"||%04d|| ||-|| ||%s||"||%|(num,ligne)
    I want to provide login and password via python code. The web adress
    is like http://website.com:8081/ddts/ddts_main.
    If you have link it is welcome!

    Regards
    Karim


    _______________________________________________
    Tutor maillist -Tutor at python.org
    To unsubscribe or change subscription options:
    http://mail.python.org/mailman/listinfo/tutor
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/tutor/attachments/20110128/048c3667/attachment.html>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouptutor @
categoriespython
postedJan 28, '11 at 9:54p
activeJan 28, '11 at 10:33p
posts5
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase