Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5945185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:38:45+00:00 2026-05-22T16:38:45+00:00

I’ve a web application that accesses multiple controller classes based on the parameters it

  • 0

I’ve a web application that accesses multiple controller classes based on the parameters it is passed. For some of the controllers, I want users to authenticate themselves (by simple HTTP authentication), and for some I want public access.

Is there a way to make this happen? In my .htaccess file, I now have

AddHandler mod_python .py
PythonHandler handler
PythonAuthenHandler handler
PythonDebug On

AuthType Basic
AuthName "My Realm"
AuthBasicAuthoritative Off
require valid-user

The authenhandler is called correctly, but even when I just do

def authenhandler(req): 
    return apache.OK

the user is asked for a password (though any password that is entered is accepted)

I tried removing the Auth* stuff (and the require directive) from the .htaccess entirely, and just did the following in the normal handler for those cases where I do want authentication (and it was not found):

request.err_headers_out.add('WWW-Authenticate', 'Basic realm="My Realm")
return apache.HTTP_UNAUTHORIZED

which is what I understand what the server should do when not receiving correct authentication. That did not work either, however.

I come from a PHP background and I know that the latter is how it’s done in PHP – but PHP sometimes does extra little pieces of undocumented magic to make this stuff actually work. Is this one of those cases?

Is there any way to optionally request authentication, depending on the URL passed, from the same handler?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:38:46+00:00Added an answer on May 22, 2026 at 4:38 pm

    There are a couple ways to specify authentication scope with Apache, the one most people are used to is gt;Directorylt; based – i.e. anything in or below a directory gets authenticated against htpasswd.

    There’s also gt;Locationlt;, which applies directives to content that live outside the filesystem such as mod_python registered code.

    This is how you can set authentication on a ‘virtual’ path like /status, if you have mod_status enabled.

    You can do the same thing with mod_python paths

    <Location /python/app1/>
       Order allow,deny
       Allow from all
    </Location>
    
    <Location /python/app2/>
       Order allow,deny
       Allow from all
       AuthType             basic
       AuthName             "Protected Intranet Area"
       AuthUserFile         /etc/apache2/htpasswd
       Require              valid-user
    </Location>
    

    I should add – it’s not necessarily clear if you mean ‘some users should authenticate with a username and password and other users should only have to put in a username’

    or

    ‘some applications should require authentication 100% of the time, and other applications should be freely available 100% of the time’

    My first answer sorts out the last query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.