473,412 Members | 2,293 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,412 software developers and data experts.

Web authentication

Good morning to all!

I'm trying to access on a web page that needs user and password
authentication. I'm enabled to access there (I mean that I have an
user name and a password to access via web), but I cannot access using
an automatic procedure (that is what I need to make a daemon that
downloads weekly an ASCII file from that site).

I've tried using urllib:

import urllib

conn = urlib.urlopen("http://user:pa******@www.mysite.com")
print conn.read()

But it doesn't work (it asks me again user and password).

Does anybody know how can I acces to my site with authentication?

I think that urllib2 can help me but I don't undestand how!!!

Thaks

Luigi
Jul 18 '05 #1
7 2955
"luigipaioro" <lu*********@libero.it> writes:
Good morning to all!
Good morning! No need to post twice, BTW.

I'm trying to access on a web page that needs user and password
authentication. I'm enabled to access there (I mean that I have an
user name and a password to access via web), but I cannot access using
an automatic procedure (that is what I need to make a daemon that
downloads weekly an ASCII file from that site).

I've tried using urllib:

import urllib

conn = urlib.urlopen("http://user:pa******@www.mysite.com")
print conn.read()

But it doesn't work (it asks me again user and password).


That URL should work for "Basic HTTP authentiation" using urllib (I
think -- I always use urllib2, so not certain about urllib). For some
reason, a quick glance at the code suggests it *won't* work with
urllib2, but it's easy enough to achieve the same result with that
module (see the link below for how). The page you're accessing may
need some other means of authentication, though.

When you log in manually, does your browser pop up a little, rather
plain-looking, separate window? Or do you type directly into a form
on the web page itself? If the former, it's probably Basic auth., and
what you're doing should work (or, unlikely, Digest auth., in which
case I think you need urllib2). If the latter, you probably need to
submit an HTML form in the web page to log in.

Some examples on auth and proxies with urllib2 (beware: I don't use a
proxy or basic / digest auth. very often, so these are untested
examples: if you use them, *please* comment on them to say whether
they do or do not work as advertised):

http://www.python.org/sf/798244
To fill in HTML forms, you can use urllib2.urlopen(url,
urllib.urlencode(...read the docs <wink>...)), or, if you want Python
to parse the form(s) for you and/or don't want to know the messy
details of HTML forms, you could use

http://wwwsearch.sf.net/ClientForm/

You may also find you need to handle HTTP cookies:

http://wwwsearch.sf.net/ClientCookie/
John
Jul 18 '05 #2
"luigipaioro" <lu*********@libero.it> writes:
Does anybody know how can I acces to my site with authentication?

I think that urllib2 can help me but I don't undestand how!!!


It's documented in the manual. Try something like (untested):

import urllib

class Open_with_auth(urllib.FancyURLopener):
def prompt_user_passwd(self, host, realm):
return ('username', 'userpassword') # the uid and passwd you want to use

urllib._urlopener = Open_with_auth()
Jul 18 '05 #3
Paul Rubin <http://ph****@NOSPAM.invalid> writes:
"luigipaioro" <lu*********@libero.it> writes:
Does anybody know how can I acces to my site with authentication?

I think that urllib2 can help me but I don't undestand how!!!


It's documented in the manual. Try something like (untested):

import urllib

class Open_with_auth(urllib.FancyURLopener):
def prompt_user_passwd(self, host, realm):
return ('username', 'userpassword') # the uid and passwd you want to use

urllib._urlopener = Open_with_auth()


Doesn't/shouldn't http://user:pa****@example.com/blah.html work?

I don't know where that syntax is specified (if anywhere) -- do you
know, Paul? It seems at a glance that urllib understands that syntax
for ordinary Basic Auth., where urlib2 only knows it as a syntax for
proxy Basic Auth., but I may be wrong there...
John
Jul 18 '05 #4
jj*@pobox.com (John J. Lee) writes:
Doesn't/shouldn't http://user:pa****@example.com/blah.html work?
It ought to but I don't know if urllib supports it. I've always done
it the other way, with that FancyURLOpener subclass.
I don't know where that syntax is specified (if anywhere) -- do you
know, Paul?


Part of the http spec.
Jul 18 '05 #5
[John J. Lee]
Doesn't/shouldn't http://user:pa****@example.com/blah.html work?

I don't know where that syntax is specified (if anywhere)


RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax

Section: 3.2.2. Server-based Naming Authority

Quoting from that section

"""
URL schemes that involve the direct use of an IP-based protocol to
a
specified server on the Internet use a common syntax for the server
component of the URI's scheme-specific data:

<userinfo>@<host>:<port>

where <userinfo> may consist of a user name and, optionally,
scheme-
specific information about how to gain authorization to access the
server. The parts "<userinfo>@" and ":<port>" may be omitted.

server = [ [ userinfo "@" ] hostport ]

The user information, if present, is followed by a commercial
at-sign
"@".

userinfo = *( unreserved | escaped |
";" | ":" | "&" | "=" | "+" | "$" | "," )

Some URL schemes use the format "user:password" in the userinfo
field. This practice is NOT RECOMMENDED, because the passing of
authentication information in clear text (such as URI) has proven
to
be a security risk in almost every case where it has been used.
"""

regards,

--
alan kennedy
------------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/contact/alan
Jul 18 '05 #6
Alan Kennedy <al****@hotmail.com> writes:
[John J. Lee]
Doesn't/shouldn't http://user:pa****@example.com/blah.html work?

I don't know where that syntax is specified (if anywhere)


RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax

Section: 3.2.2. Server-based Naming Authority

Quoting from that section

"""
URL schemes that involve the direct use of an IP-based protocol to
a
specified server on the Internet use a common syntax for the server
component of the URI's scheme-specific data:

<userinfo>@<host>:<port>

[...]

Oops, how did I miss that?

Thanks
John
Jul 18 '05 #7
Hey guys, i was just googling some information about how to use the ClientForm package with a page which requires HTTP basic authentication and i got here :P ... So here is the problem, lets see if anyone here can help me please solving this issue :)

First i open the protected page using the FancyURLopener which support the HTTP basic authentication and pass this object to the ParseResponse function so it parses the corresponding forms :P

opener = urllib.FancyURLopener({})
URLStream = opener.open ( FormURL )

forms = ParseResponse(URLStream, backwards_compat=False)
form = forms[0]

Well, now here i fill in the form ... And finally i try to make the post using the ClientForm objects:

request2 = form.click()
response2 = urllib2.urlopen(request2)

The problem here is that i get the following exception:

"httplib.InvalidURL: nonnumeric port: 'XXXXXXXXXXXX@www.domain.com'"

I think that the problem here is that the ClientForm when calling click() tries to build a common urllib Request object which is obvious can't be done cause the provided url to the FancyURLopener which is from were the ClientForm retrieves the url for the Request object has the url username and password :(

So ... Can someone give me some hints or even better some example code to deal with this issue ?

Ps: I don't seem to have a .py file but a .egg file for the ClientForm package so i'm not able to debug or change the ClientForm source :(

/s
Mar 27 '06 #8

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

Similar topics

7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
8
by: Bob Everland | last post by:
I have an application that is ISAPI and the only way to secure it is through NT permissions. I need to have a way to login to windows authentication so that when I get to the ISAPI application no...
6
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms...
9
by: Tom B | last post by:
In my web.config file I've specified Windows for the authentication, in IIS I've set it to Integrated Authentication. But my SQL connection is still showing Anonymous. Is there somewhere else I...
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
4
by: Andrew | last post by:
Hey all, I would like to preface my question by stating I am still learning ASP.net and while I am confident in the basics and foundation, the more advanced stuff is still a challenge. Ok....
0
by: Albertas | last post by:
What I'm doing wrong that I can't make my authentication to work. Here is the situation: I'm hosting a Web Service from a Windows forms application, using .NET Framework 3.0 WCF. And I want to...
18
by: troywalker | last post by:
I am new to LDAP and Directory Services, and I have a project that requires me to authenticate users against a Sun Java System Directory Server in order to access the application. I have found...
2
by: Frank Swarbrick | last post by:
I am trying to understand "client authentication" works. My environment is DB2/UDB LUW 8.2 on zSeries SLES9 as the database server and DB2 for VSE 7.4 as the client. We currently have DB2/LUW set...
5
by: Rory Becker | last post by:
Having now created a Custom MembershipProvider that seems to work correctly with my Logon and ChangePassword controls, I am, as they say, a happy bunny. The next stange is to move on to the...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.